wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Whiz Lab Question On THreads 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 "Whiz Lab Question On THreads" Watch "Whiz Lab Question On THreads" New topic
Author

Whiz Lab Question On THreads

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

Whiz lab Quesiton



output:
abc

i have some doubt's

1.is the output 123 possible
2.can it's output be predicted
3.
Does it mean anything?


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

mohitkumar gupta wrote:

1.is the output 123 possible

No. Did you check the JLS? With the sleep method, the thread who already acquired the lock, doesn't loose it!
mohitkumar gupta wrote:
2.can it's output be predicted

Yes, in this case!
mohitkumar gupta wrote:
3.
Does it mean anything?


The main thread get the lock of the object o.

And, for a exercise, change the sleep() method to wait() method on the object!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

BTW, here is the JLS
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

1.
Why can't thread t1 start ??
2.
why do thread t1 require lock on o to run ??
3.
thread t1 start inside the synchronized block,why would it require lock ???
4.
how is main thread acquiring lock on o and not t1 ???



Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

mohitkumar gupta wrote:1.
Why can't thread t1 start ??
2.
why do thread t1 require lock on o to run ??
3.
thread t1 start inside the synchronized block,why would it require lock ???
4.
how is main thread acquiring lock on o and not t1 ???


Dude, go through the Threads chapter once again. This is my advise!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Whiz Lab Question On THreads
 
Similar Threads
Thread Question??
Threads: synchronizing a block of code (K&B 1.5)
Whiz Lab MOCK Quesitions on THREADS
Thread Question about sleep method
Synchronization of run method