1.7.6 method Stop () and Java.lang.threadDeath exception

Source: Internet
Author: User

A Java.lang.ThreadDeath exception is thrown when the stop method is called, but in general this exception does not need to show the snapping

1  PackageCom.cky.thread;2 3 /**4 * Created by Edison on 2017/12/3.5  */6  Public classMyThreadextendsthread{7 @Override8      Public voidrun () {9         Super. Run ();Ten         Try { One             This. Stop (); A}Catch(Threaddeath e) { - e.printstacktrace (); -         } the     } -}
1  Packagecom.cky.test;2 3 ImportCom.cky.thread.MyThread;4 5 /**6 * Created by Edison on 2017/12/3.7  */8  Public classTest {9      Public Static voidMain (string[] args) {TenMyThread th =NewMyThread (); One Th.start (); A     } -}
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 # Multithreading Core technologyThe first chapter \out\production\ the first chapter; 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 code0

Method Stop is obsolete

Because forcing a thread to stop will cause some cleanup work to be done, and another is to unlock the locked object, resulting in data not being synchronized and inconsistent with the data.

1.7.6 method Stop () and Java.lang.threadDeath exception

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.