About Question enthuware.ocpjp.v7.2.1296 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

About Question enthuware.ocpjp.v7.2.1296 :

Post 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.

sinapse
Posts: 27
Joined: Sat Aug 31, 2013 5:38 pm
Contact:

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

Post by sinapse »

There are two threads in the example not only one !

EpicWestern
Posts: 17
Joined: Wed Jan 22, 2014 12:35 pm
Contact:

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

Post by EpicWestern »

sinapse wrote:There are two threads in the example not only one !
He's saying after thread t is finished.

Mark7777
Posts: 32
Joined: Tue Apr 12, 2016 9:19 pm
Contact:

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

Post 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

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 54 guests