This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes join() - Thread priority Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "join() - Thread priority" Watch "join() - Thread priority" New topic
Author

join() - Thread priority

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1300
join() pause the current thread and give the chance to other waiting threads. Whether waiting threads should have same Thread priority? If waiting thread is lesser Thread priority than current running thread, whether join() pause the current thread?
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
join() causes the current thread to wait for the joined thread
to commplete its run() method. Did you intend to ask about
the yield() method?
Jim ... ...


BEE MBA PMP SCJP-6
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1300
You are correct. It's yield(), not join()
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3670

It's a way of saying the current thread would like to give up CPU time in place of another thread. But you shouldn't depend on the behaviour as it's up to the thread scheduler implementation.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
vinnu kumar
Greenhorn

Joined: Sep 10, 2007
Posts: 12
If we have thread B,that cannot do its work untill thread A has completed,you join B to A.Which means B will not become runnable untill A has finished.
where as yield() is used for turn taking among equal priority threads(but that too is not guaranteed)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19


The yield() method merely passes the hint to the underlying scheduler, that it wishes to give up on its current time slice. Whether anything happens, is dependent on the scheduler.

With certain schedulers, this could mean that a lower priority thread will get a chance to run -- but if it does, it will unlikely run very long, before the scheduler context switches back to the higher priority thread.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: join() - Thread priority
 
Similar Threads
Thread execution
Section 7 mock test questions
Threads
What is the guaranteed behaviour of yield()
Thread question form MindQ