aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 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 "Threads" Watch "Threads" New topic
Author

Threads

Sireesha Mullapudi
Ranch Hand

Joined: Jun 26, 2006
Posts: 74
Hi,

Iam preparing for scjp1.4.I have doubt in locking the class Object.

My Code


My Doubt is:

I think Calling the sleep method in mtwo doesn't release the lock on class object.Then why thread t2 is able to execute mtwo() successfully.

And also,do calling wait method on class object needs notify.

Could You explain,where iam making mistake

And also give me the suggestion on complexity of threads in SCJP1.4
Thanks,
Amulya
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by lakshmi amulya:
...I think Calling the sleep method in mtwo doesn't release the lock on class object.Then why thread t2 is able to execute mtwo() successfully...

If you add some println statements to the method, you will see that t2 does not get into the synchronized block until t1 releases the lock.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by lakshmi amulya:
...And also,do calling wait method on class object needs notify...

You are calling wait with a timeout parameter of 1000. So after 1000 milliseconds without a call to notify() or notifyAll(), the thread will stop waiting. If you did not have a timeout and didn't call notify() or notifyAll()...

Well, you should be able to quit the program by pressing Ctrl+C.
Sireesha Mullapudi
Ranch Hand

Joined: Jun 26, 2006
Posts: 74
Hi Marc Weber,


Thank You very Much.I got it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads