Page 1 of 1

About Question enthuware.ocpjp.v7.2.1296 :

Posted: Tue Sep 03, 2013 3:48 am
by The_Nick
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.

Re: About Question enthuware.ocpjp.v7.2.1296 :

Posted: Fri Sep 13, 2013 4:52 pm
by sinapse
There are two threads in the example not only one !

Re: About Question enthuware.ocpjp.v7.2.1296 :

Posted: Fri Feb 07, 2014 2:56 pm
by EpicWestern
sinapse wrote:There are two threads in the example not only one !
He's saying after thread t is finished.

Re: About Question enthuware.ocpjp.v7.2.1296 :

Posted: Mon Oct 08, 2018 1:05 pm
by Mark7777
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

Re: About Question enthuware.ocpjp.v7.2.1296 :

Posted: Mon Oct 08, 2018 8:42 pm
by admin
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.