About Question enthuware.ocpjp.v7.2.1505 :

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

Moderator: admin

Post Reply
Wisevolk
Posts: 33
Joined: Thu Jul 18, 2013 6:06 pm
Contact:

About Question enthuware.ocpjp.v7.2.1505 :

Post by Wisevolk »

Hi,
The sleep method doesn't release the lock ? So can we consider the thread not be running ?

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

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

Post by admin »

Yes, even if the lock is not released, the thread is not running.
If you like our products and services, please help us by posting your review here.

fariz.siracli
Posts: 22
Joined: Mon Jul 06, 2015 11:45 am
Contact:

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

Post by fariz.siracli »

- The thread is trying to enter a synchronized block and the monitor is not free.
In this situation, the thread will be blocked until some other thread calls notify()/notifyAll() on the object whose synchronized block this thread is trying to enter.

In this case why thread trying to get monitor, will be blocked until other thread call notify()/notifyAll()? It may be the case that thread tries to get monitor for just synchronized method or block and there is no called wait method.
Isn't it possible ?

And also when some thread tries to get monitor isn't it in running state still?

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

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

Post by admin »

When the thread tries to get a monitor and if the monitor is not free, then it gets blocked. It was running but not anymore. That is how threading has been designed in Java. Only when another thread that is holding the lock notifies blocked threads, will the blocked threads will be unblocked and become ready to run again.
If you like our products and services, please help us by posting your review here.

jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

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

Post by jagoneye »

Also please note that JLS considers a running and runnable thread as 'runnable' state only.

Javatje
Posts: 9
Joined: Wed Jun 30, 2021 6:53 am
Contact:

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

Post by Javatje »

In which of the following cases a thread will definitely be alive but not be running?

The thread has issued a call to wait( ). (Assuming that the thread owns the lock for the object on which wait is called.)
In this situation, the thread will be blocked until some other thread calls notify()/notifyAll() on the object on which this thread has called wait() and this thread is able to reacquire the lock for this object.

Since the thread has already issued the call. Therefore, another thread may have called notify(), so the thread is not definitely not running.

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

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

Post by admin »

Zoom in a little :) Right after the call to main, before anything else happens, the thread is definitely not running.
If you like our products and services, please help us by posting your review here.

Javatje
Posts: 9
Joined: Wed Jun 30, 2021 6:53 am
Contact:

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

Post by Javatje »

"before anything else happens"
This is not stated in the question

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 46 guests