Hi everybody,
I think that added on the fact that notifyAll will be having effect after the synchronized block is finished, it will be printing DATA anyhow since there is only one thread, and no threads waiting.
The_Nick.
About Question enthuware.ocpjp.v7.2.1296 :
Moderator: admin
-
- Posts: 132
- Joined: Thu May 16, 2013 9:23 am
- Contact:
-
- Posts: 27
- Joined: Sat Aug 31, 2013 5:38 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1296 :
There are two threads in the example not only one !
-
- Posts: 17
- Joined: Wed Jan 22, 2014 12:35 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1296 :
He's saying after thread t is finished.sinapse wrote:There are two threads in the example not only one !
-
- Posts: 32
- Joined: Tue Apr 12, 2016 9:19 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1296 :
Is it possible for the scheduler to back the new thread out of run() after r.data = "DATA "+number; and release the lock to main which would print DATA 1, and then the scheduler allows the new thread (t) to continue? Would a scheduler ever do that, assuming it has that power? There's no wait() to gum things up.
mark
mark
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1296 :
Yes, it is possible for the scheduler to schedule the main thread right after executing r.data = "DATA "+number; of the thread t, but it will not be able to proceed further because the next line in main thread is synchronized(r). The lock to r is already held by t. So the schedular will have no option but to make the main thread wait until the lock to r is released. It will be release only after the t thread exits out of the synchronized(r) block.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 54 guests