Java中线程死亡异常的模拟
我如何在java编程中模拟threaddeath异常,在什么情况下会发生这种情况,任何人都可以举个例子,抛出threaddeath异常 谢谢:Java中线程死亡异常的模拟,java,exception,Java,Exception,我如何在java编程中模拟threaddeath异常,在什么情况下会发生这种情况,任何人都可以举个例子,抛出threaddeath异常 谢谢: public class ThreadDeathCatch { public static void main(String[] args) { try { Thread t = new Thread() { public void run() { try {
public class ThreadDeathCatch {
public static void main(String[] args) {
try {
Thread t = new Thread() {
public void run() {
try {
Thread.sleep(2500);
} catch (Throwable ex) {
ex.printStackTrace();
System.out.println("Caught in run: " + ex);
}
}
};
t.start();
// Give t time to get going...
Thread.sleep(1000);
t.stop(); // EXPECT COMPILER WARNING
} catch (Throwable t) {
System.out.println("Caught in main: " + t);
}
}
}
这是抛出Threaddeath的示例,它使用Thread.stop是否存在其他错误情况,即在不使用Thread.stop的情况下,多线程环境中会发生线程死亡。stop
有什么想法吗
你的问题至少有一半可以通过阅读来回答。你的具体问题是什么?我需要一个直播节目来抛出threaddeathexception@anish:尝试
抛出新的ThreadDeath()代码>。
System.out.println("Trying to kill current thread");
try {
Thread.currentThread().stop();
} catch (final ThreadDeath ex) {
System.out.println("Ugh I'm dead");
throw ex;
}