wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Alive?-->JQ+ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Alive?-->JQ+" Watch "Thread Alive?-->JQ+" New topic
Author

Thread Alive?-->JQ+

Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
Question ID :952739433290
In which of the following cases a thread will definitely be alive but not be running?
1:The thread has issued a call to notify
2:The thread is trying to enter a synchronized block & the montior is not free
3:A higher priority thread comes in ready to run state
4:The thread is sleeping as a result of a call to sleep() method
5:The thread calls yield()
I have selected 1,2,5.But it says correct answer is 1,2,4.A/c to me 1,2,4,5 are true statement.A thread which calls yield() has two option,either continue to run or move to readyu state.I think in both conditions Thread is Alive.If a tread call sleep() then it moves to wiat state,which is also alive.
My concept about alive: A thread is alive after it calls start() & before it just calls stop() or just before entering dead state.
UR Views are required!
------------------
Count the flowers of ur garden,NOT the leafs which falls away!


Count the flowers of your garden, NOT the leafs which falls away!
Prepare IBM Exam 340 by joining http://groups.yahoo.com/group/IBM340Exam/
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Well, you never know with yield since what happens depends on the scheduler. If you invoke yield on the Thread class, the current thread is not necessarly paused. It is moved from RUNNING to READY state but may as well be moved to RUNNING again if no threads are eligible to run right now. So I'd say 5 is not true given the wording of the question.
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
U mean that thread in ready state are not alive?
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Don't get me wrong, threads in READY state are alive. But making the current thread yield doesn't mean that it will do so, it may as well be the current thread again (depending on the scheduler). So calling yield may not prevent the current thread from running...
JQ+'s explanations is that yield() does not necessarly put the calling thread on hold... It all depends on the OS.
Pay attention to the "not be running" of the question, that's the key here !
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform

[This message has been edited by Valentin Crettaz (edited December 14, 2001).]
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
Got It!.Thanx Valentin Once again.Ok now i am going to generalize the active state of thread.Please correct me if i am wrong(as u alwayz )
These scenarios are from cert. point of view.Means i know there is a condition that thread is active before start() is call,but i think cert. is not going to ask that scenario for acive * unactive.Here u mentioned that scenario,http://www.javaranch.com/ubb/Forum24/HTML/013618.html
OK...
Thread is active just after start() is call & just before it leaves for dead state.In all other state thread is not alive
Bye
Viki.
[This message has been edited by Vikrama Sanjeeva (edited December 14, 2001).]
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
I disagree with 1 because a thread stills owns the monitor and thefore is running after calling notify. Only when calling wait on itself will the thread be releasing the monitor and stay blocked.


SCJP2. Please Indent your code using UBB Code
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Jose,
when a Thread invokes wait it is not running anymore, it is in the WAITING state waiting to be notified, times out or be interrupted.
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
to Val
But ans 1 says notify not wait...
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Sorry, my mistake...
an invocation of notify does not necessarly prevent the invoking thread from running if no other thread are notified.
Does it make sense ?
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
yes the thread will continue running until it will invoke wait on itself to allow the previously notified threads to enter the "competition" for getting the lock.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3308
    
    7
calling notify() indeed does not stop/pause the thread. However, I checked the question and option 1 says, "The thread has issued a call to wait( )."
Vikarma, can you please double check?


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
Paul what do u mean by double check?.
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3308
    
    7
Ok..sorry, just check it again You can use Advanced->View Question and enter the question id to view the question.
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
I have checked the question infact double checke .It is same as i mentioned above.
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Question ID :952739433290
In which of the following cases a thread will definitely be alive but not be running?

The thread has issued a call to wait()
A higher priority ...
The thread is trying ...
The thread is sleeping ...
The thread calls yield()


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
Ok i have checked now thrice,but it was the same as i mentioned above.I cant get the version of JQ+,when i click help-->About JQ+ i haven't got anything showing version.Now plz. confirm that if it is notify() then option 1 is correct & if it is wait() then option 1 is incorrect.?
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
I've checked on mine and it says :

The thread has issued a call to wait()
...


------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3308
    
    7
Vikrama, when did you buy it?
You can send your orderid to jqplus_s@hotmail.com to get the latest version.
HTH,
Paul.
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
Paul i haven't purchased it.Its my brother who sent me .How can i know that which version i am using & which version is latest?.
I have 618 question bank.
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3308
    
    7
Well, that is old. We released a new one about 2 months ago that contains 700 questions.
However, I also checked the question in a very old version (with 591 questions) and there also, it says "wait". So, I am not sure how are you getting "notify".
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
Ok Paul how can i get the latest version of JQ+.And what is the difference b/w the latest one & old one.?
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
 
GeeCON Prague 2014
 
subject: Thread Alive?-->JQ+