(1) Concurrent Java programs can exhibit deterministic behavior, by providing mechanisms for synchronizing. (2) Threads have parent-child relationships. (3) When the thread is created, it is not yet active
a. 1 and 3 b. All 3 c. 1 and 2
The given answer is a.but why 2 is not included.Please i am looking for the rules?Option 1 expalnation too.
1) Is true. When multi-threaded code isn�t correctly synchronised, non-deterministic and unexpected behaviour can occur.
2) Is false, because as far as I know only processes in the system have parent-child relationship. A thread is a single sequential flow of control within a process (also named lightweight process). Threads in a process have no parent-child relationship with each other.
3) is true (I think �active� means �running�). A call to start() will not immediately start thread's execution. It will move it to the ready-to-run pool. Based on the thread priorities, the thread scheduler will pick one of the ready-to-run threads and the thread will enter the running-state.
Hope I�m right and this explanation will help you.
Originally posted by Andrea Z�rcher: ...1) Is true. When multi-threaded code isn�t correctly synchronised, non-deterministic and unexpected behaviour can occur...
Yes, but I think the question is how synchronization might change this.
When multiple Java threads are running, it's up to the thread scheduler to determine when each thread will get a chance to run. This can result in somewhat unpredictable behavior. Synchronized code requires a thread to get the lock before proceeding, so this can force threads to wait if another thread has the lock.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
posted 13 years ago
Thanks for the detailed explanation Andrea and marc.