• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

tipsmart mock question

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
State which of the following statements are True.

(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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shiva

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.

Andrea
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the detailed explanation Andrea and marc.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic