yield()方法:
A hint to the scheduler that the current thread is willing to yield its current use of a processor. The scheduler is free to ignore this hint
一个暗示:当前的调度程序愿意放弃当前使用的处理器,而且调度程序可以忽略这个提示
Yield is a heuristic attempt to improve relative progression between threads that would otherwise over-utilise a CPU. Its use should be combined with detailed profiling and benchmarking to ensure that it actually has the desired effect.
Yield是一个启发式尝试去促进相对的前进在几个进程之间
It is rarely appropriate to use this method.(适当少用这个方法)It may be useful for debugging or testing purposes, where it may help to reproduce bugs due to race conditions. It may also be useful when designing concurrency control constructs such as the ones in thejava.util.concurrent.locks
package.
sleep()方法
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds,subjectto the precision and accuracy of system timers and schedulers.The thread does not lose ownership of any monitors.
start()方法
Causes this thread to begin execution;the java virtual machine calls the runmethod of run method of this method
The result is that two thread are running concurrently
It is never legal to start a thread more than noce , in particular ,a thread may not be started once it has completed execution(当一个线程结束后,不能再次启动)
run()
If this thread was constructed using a separate Runnable run object ,then that Runnable object'run methods is called ;others ,this method does nothing and returns
Subclass of thread shoule override this method
join()
-
Waits at most
millis
milliseconds for this thread to die. A timeout of0
means to wait forever.This implementation uses a loop of
this.wait
calls conditioned onthis.isAlive
. As a thread terminates thethis.notifyAll
method is invoked. It is recommended that applications not usewait
,notify
, ornotifyAll
onThread
instances.
public void interrupt():
Unless the current thread is interrupting itself, which is always permitted, the
checkAccess
method of this thread is invoked, which may cause aSecurityException
to be thrown.If this thread is blocked in an invocation of the
wait()
,wait(long)
, orwait(long, int)
methods of theObject
class, or of thejoin()
,join(long)
,join(long, int)
,sleep(long)
, orsleep(long, int)
, methods of this class, then its interrupt status will be cleared and it will receive anInterruptedException
.If this thread is blocked in an I/O operation upon an
interruptible channel
then the channel will be closed, the thread's interrupt status will be set, and the thread will receive a
ClosedByInterruptException
.If this thread is blocked in a
Selector
then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector'swakeup
method were invoked.If none of the previous conditions hold then this thread's interrupt status will be set.
Interrupting a thread that is not alive need not have any effect.
public boolean isInterrupted():发生改变了
A thread interruption ignored because a thread was not alive at the time of the interrupt will be reflected by this method returning false.
public static boolean interrupted():
A thread interruption ignored because a thread was not alive at the time of the interrupt will be reflected by this method returning false.