Java Reference
In-Depth Information
that the number of processors can change at any time, so you want to
check this number when it is important rather than remember the num-
ber from a previous check.
14.6.1. Voluntary Rescheduling
Several methods of the Thread class allow a thread to relinquish its use
of the CPU . By convention, static methods of the THRead class always ap-
ply to the currently executing thread, and since you can never take the
CPU from another thread, these voluntary rescheduling methods are all
static:
public static void sleep(long millis) tHRows InterruptedException
Puts the currently executing thread to sleep for at least the
specified number of milliseconds. "At least" means there is
no guarantee the thread will wake up in exactly the specified
time. Other thread scheduling can interfere, as can the granu-
larity and accuracy of the system clock, among other factors.
If the thread is interrupted while it is sleeping, then an Inter-
ruptedException is thrown.
public static void sleep(long millis, int nanos) tHRows Interrup-
tedException
Puts the currently executing thread to sleep for at least the
specified number of milliseconds and nanoseconds. Nano-
seconds are in the range 0999999.
public static void yield()
Provides a hint to the scheduler that the current thread need
not run at the present time, so the scheduler may choose an-
other thread to run. The scheduler may follow or ignore this
suggestion as it sees fityou can generally rely on the sched-
 
Search WWH ::




Custom Search