• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Couple of Thread Qs from JQPlus

 
Himanshu Jhamb
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers.
These are just some snippets from a couple of JQ+ thread Qs.
Q1) When a thread calls notify() from within its synchronized block, does it say to the waiting threads that "Hey! Guys, I am relinquishing the lock on this object." & actually does so ?
Q2) Can a join operation on a thread cause some other thread to stop?
Thanks
- Himanshu
 
Rob Ross
Bartender
Posts: 2205
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A1) No. Unlike wait(), which blocks immediately and gives up its lock, notify() and notifyAll() won't actually give up the lock on the object until execution exits the synchronized block in which the notify()/notifyAll() is located.
Example:
...
synchronized(this){
//do stuff
notify(); //thread not block, nor locks surrendered
//do more stuff
} //end of synchronized block, thread gives up locks

A2) Yes. Calling join() on thread A causes the current thread to be suspended until thread A completes, at which time the thread that invoked join() will continue.
 
Muhammad Usman
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are other version of the join(), which waits for milli seconds, for a thread to complete, then starts whether or not calling thread has got its execution complete or not.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic