1.7.6方法stop()與java.lang.threadDeath異常

來源:互聯網
上載者:User

標籤:led   stack   pac   over   dep   data   void   span   jce   

調用stop方法時會拋出java.lang.ThreadDeath異常,但一般情況下這個異常不需要顯示的捕捉

 1 package com.cky.thread; 2  3 /** 4  * Created by edison on 2017/12/3. 5  */ 6 public class MyThread extends Thread{ 7     @Override 8     public void run() { 9         super.run();10         try {11            this.stop();12         } catch (ThreadDeath e) {13             e.printStackTrace();14         }15     }16 }
 1 package com.cky.test; 2  3 import com.cky.thread.MyThread; 4  5 /** 6  * Created by edison on 2017/12/3. 7  */ 8 public class Test { 9     public static void main(String[] args) {10             MyThread th = new MyThread();11             th.start();12     }13 }
C:\itsoft\jdk\bin\java -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:\itsoft\idea\IntelliJ IDEA 2016.3.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\itsoft\jdk\jre\lib\charsets.jar;C:\itsoft\jdk\jre\lib\deploy.jar;C:\itsoft\jdk\jre\lib\ext\access-bridge-32.jar;C:\itsoft\jdk\jre\lib\ext\cldrdata.jar;C:\itsoft\jdk\jre\lib\ext\dnsns.jar;C:\itsoft\jdk\jre\lib\ext\jaccess.jar;C:\itsoft\jdk\jre\lib\ext\jfxrt.jar;C:\itsoft\jdk\jre\lib\ext\localedata.jar;C:\itsoft\jdk\jre\lib\ext\nashorn.jar;C:\itsoft\jdk\jre\lib\ext\sunec.jar;C:\itsoft\jdk\jre\lib\ext\sunjce_provider.jar;C:\itsoft\jdk\jre\lib\ext\sunmscapi.jar;C:\itsoft\jdk\jre\lib\ext\sunpkcs11.jar;C:\itsoft\jdk\jre\lib\ext\zipfs.jar;C:\itsoft\jdk\jre\lib\javaws.jar;C:\itsoft\jdk\jre\lib\jce.jar;C:\itsoft\jdk\jre\lib\jfr.jar;C:\itsoft\jdk\jre\lib\jfxswt.jar;C:\itsoft\jdk\jre\lib\jsse.jar;C:\itsoft\jdk\jre\lib\management-agent.jar;C:\itsoft\jdk\jre\lib\plugin.jar;C:\itsoft\jdk\jre\lib\resources.jar;C:\itsoft\jdk\jre\lib\rt.jar;C:\多線程核心技術\第一章\out\production\第一章;C:\itsoft\idea\IntelliJ IDEA 2016.3.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.cky.test.Testjava.lang.ThreadDeath    at java.lang.Thread.stop(Thread.java:853)    at com.cky.thread.MyThread.run(MyThread.java:12)Process finished with exit code 0

方法stop已經作廢

因為如果強制讓線程停止則會使得一些清理性的工作得不到完成,另外一個就是對鎖定對象進行解鎖,導致資料得不到同步處理,出現資料不一致。

1.7.6方法stop()與java.lang.threadDeath異常

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.