java.lang.Thread

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 of 0 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, or notifyAll on Thread instances.

当当前线程终止的时候,系统会自动调用该线程的notifyAll()方法,唤醒阻塞在该线程上的所有线程

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 a SecurityException to be thrown.

If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException.

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's wakeup 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():发生改变了

Tests whether this thread has been interrupted . The interrupted status of the thread is unaffected by this method.

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():

Tests whether the current thread has been interrupted. The interrupted status of the thread is cleared by this method. In other words, if this method were to be called twice in succession, the second call would return false (unless the current thread were interrupted again, after the first call had cleared its interrupted status and before the second call had examined it).

A thread interruption ignored because a thread was not alive at the time of the interrupt will be reflected by this method returning false.

 

 

 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值