Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about Threads

 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic