zoukankan      html  css  js  c++  java
  • Thread类的interrupted方法和isInterrupted方法的区别

     如下所示,interrupted()会改变线程的中断状态(清除),而isInterrupted()不影响线程的中断状态

     
     1    /** * Tests whether the current thread has been interrupted.  The 
    * <i>interrupted status</i> 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).
    * * <p>A thread interruption ignored because a thread was not alive
    * at the time of the interrupt will be reflected by this method
    * returning false.
    * *
    @return <code>true</code> if the current thread has been interrupted;
    * <code>false</code> otherwise. *
    @see #isInterrupted() * @revised 6.0 */

    public static boolean interrupted() { 2 return currentThread().isInterrupted(true); 3 } 4 5 6 /** * Tests whether this thread has been interrupted. The <i>interrupted
    * status</i> of the thread is unaffected by this method.
    * * <p>A thread interruption ignored because a thread was not alive
    * at the time of the interrupt will be reflected by this method
    * returning false. * *
    @return <code>true</code> if this thread has been interrupted;
    * <code>false</code> otherwise. *
    @see #interrupted() * @revised 6.0 */

    public boolean isInterrupted()
    { return isInterrupted(false);} 7 8 9 10 /** * Tests if some Thread has been interrupted. The interrupted state
    * is reset or not based on the value of ClearInterrupted that is * passed.
    */

    private native boolean isInterrupted(boolean ClearInterrupted);
  • 相关阅读:
    用kettle做ETL时设置mysql连接参数使数据写入速度加快
    infobright社区版rpm包
    mysql在大数据量下性能调优相关参数
    greenplum给某个用户赋予整个schema下所有表的权限
    Linux挂载大于2T的磁盘硬盘
    Centos 系统swap(虚拟内存)管理
    域内
    随便记录一些东西
    有关终端的一些tips
    精悍的指令
  • 原文地址:https://www.cnblogs.com/jiangz222/p/4722356.html
Copyright © 2011-2022 走看看