wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question about 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 "A question about Threads" Watch "A question about Threads" New topic
Author

A question about Threads

Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Assume that there are two threads: t1, t2. If t1 has more priority over t2, is that an assurrance that t1 will completely finish before t2 will start executing...or we need a synchronized method to achieve that. By the way, can we designate the run method itself as synchronized so that one thread is finished before second starts. Or we need a deeper level synchronized method called from run() to accomplish such behaviour.
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Here is one reply from Anthony:
quote:
--------------------------------------------------------------------------------
Originally posted by Barkat Mardhani:
Another question: assume that there are two explicit threads: t1, t2. If t1 has more priority over t2, is that an assurrance that t1 will completely finish before t2 will start executing...or we need a synchronized method to achieve that. By the way, can we designate the run method itself as synchronized so that one thread is finished before second starts. Or we need a deeper level synchronized method called from run() to accomplish such behaviour.
--------------------------------------------------------------------------------
Setting a thread at a high priority will not guarantee that it finishes first. Try it by editing out the line after #1. To enable threads to accomplish tasks in a certain order, you can use join(). The thread that invokes join() will be allowed to finish first, as Jim mentioned in another, ah, thread...


[ September 02, 2002: Message edited by: Thomas Paul ]
 
 
subject: A question about Threads
 
Similar Threads
Working of notify()/wait()
Threads with static variables
Thread Behavour
Deadlocks in Threads?
Thread behavior with synchronized method