
Java 的问题泣血跪求求大虾指导 这个异常是什么意思的,到底什么情况下就会出现这种异常的?
Exceptionwhileremovingreference:java.lang.InterruptedExceptionjava.lang.InterruptedEx...
Exception while removing reference: java.lang.InterruptedException
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at sun.java2d.Disposer.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
很感谢你的回答
我还想知道,如果只是中断的话,这个异常对程序的影响大不大的?有没有什么办法可以解决的?积分方面绝不会让你吃亏的。呵呵 展开
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at sun.java2d.Disposer.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
很感谢你的回答
我还想知道,如果只是中断的话,这个异常对程序的影响大不大的?有没有什么办法可以解决的?积分方面绝不会让你吃亏的。呵呵 展开
6个回答
展开全部
简单的说就是:假如有两个线程,第一个线程正在运行,第二个没有运行,这时第二个线程启动运行并要求中断第一个线程,第一个线程就会出现InterruptedException异常并执行该异常下的语句。
经典线程代码:
package threadgroup;
class ThreadDemo3 extends Thread {
private String name;
private int delay;
public ThreadDemo3(String sname, int i_delay) {
name = sname;
delay = i_delay;
}
public void run() {
try {
sleep(delay);
} catch (InterruptedException e) {
}
System.out.println("多线程测试!\n" + name + "\n" + delay);
}
}
public class testMyThread {
public static void main(String[] args) {
ThreadDemo3 th1,th2,th3;
th1 = new ThreadDemo3("线程1", (int) (Math.random() * 900));
th2 = new ThreadDemo3("线程2", (int) (Math.random() * 900));
th3 = new ThreadDemo3("线程3", (int) (Math.random() * 900));
th1.start();
th2.start();
th3.start();
}
}
package threadgroup;
public class threadDemo {
public static void main(String[] args) {
Thread t = Thread.currentThread();
t.setName("你好吗?");
System.out.println("正在进行的Thread是:" + t);
try {
for (int i = 0; i < 5; i++) {
System.out.println("我不是XXX" + i);
Thread.sleep(3000);
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("Thread has wrong" + e.getMessage());
}
}
}
package threadgroup;
public class threadDemo2 implements Runnable {
public threadDemo2() {
Thread t1 = Thread.currentThread();
t1.setName("第一个主进程");
System.out.println("正在运行" + t1);
Thread t2 = new Thread(this, "");
System.out.println("在创建一个进程");
t2.start();
try {
System.out.println("使他进入第一个睡眠状态");
Thread.sleep(2000);
} catch (InterruptedException e) {
System.out.println("Thread has wrong" + e.getMessage());
}
System.out.println("退出第一个进程");
}
public void run() {
try {
for (int i = 0; i < 5; i++) {
System.out.println("进程" + i);
Thread.sleep(3000);
}
} catch (InterruptedException e) {
// TODO: handle exception
System.out.println("Thread has wrong" + e.getMessage());
}
System.out.println("退出第二个进程");
}
public static void main(String[] args) {
new threadDemo2();
}
}
经典线程代码:
package threadgroup;
class ThreadDemo3 extends Thread {
private String name;
private int delay;
public ThreadDemo3(String sname, int i_delay) {
name = sname;
delay = i_delay;
}
public void run() {
try {
sleep(delay);
} catch (InterruptedException e) {
}
System.out.println("多线程测试!\n" + name + "\n" + delay);
}
}
public class testMyThread {
public static void main(String[] args) {
ThreadDemo3 th1,th2,th3;
th1 = new ThreadDemo3("线程1", (int) (Math.random() * 900));
th2 = new ThreadDemo3("线程2", (int) (Math.random() * 900));
th3 = new ThreadDemo3("线程3", (int) (Math.random() * 900));
th1.start();
th2.start();
th3.start();
}
}
package threadgroup;
public class threadDemo {
public static void main(String[] args) {
Thread t = Thread.currentThread();
t.setName("你好吗?");
System.out.println("正在进行的Thread是:" + t);
try {
for (int i = 0; i < 5; i++) {
System.out.println("我不是XXX" + i);
Thread.sleep(3000);
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("Thread has wrong" + e.getMessage());
}
}
}
package threadgroup;
public class threadDemo2 implements Runnable {
public threadDemo2() {
Thread t1 = Thread.currentThread();
t1.setName("第一个主进程");
System.out.println("正在运行" + t1);
Thread t2 = new Thread(this, "");
System.out.println("在创建一个进程");
t2.start();
try {
System.out.println("使他进入第一个睡眠状态");
Thread.sleep(2000);
} catch (InterruptedException e) {
System.out.println("Thread has wrong" + e.getMessage());
}
System.out.println("退出第一个进程");
}
public void run() {
try {
for (int i = 0; i < 5; i++) {
System.out.println("进程" + i);
Thread.sleep(3000);
}
} catch (InterruptedException e) {
// TODO: handle exception
System.out.println("Thread has wrong" + e.getMessage());
}
System.out.println("退出第二个进程");
}
public static void main(String[] args) {
new threadDemo2();
}
}
2010-12-06
展开全部
如果你保证你的代码没有问题的话,我建议你对jdk的版本看看,这是线程的问题,一般跟代码没有关系,建议重新下载jdk,重新配置,再试试。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class InterruptedExceptionextends Exception当线程在活动之前或活动期间处于正在等待、休眠或占用状态且该线程被中断时,抛出该异常。有时候,一种方法可能希望测试当前线程是否已被中断,如果已被中断,则立即抛出此异常。下列代码可以达到这种效果:
if (Thread.interrupted()) // Clears interrupted status!
throw new InterruptedException();
if (Thread.interrupted()) // Clears interrupted status!
throw new InterruptedException();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我觉得你把整个程序贴出来,然后再问具体的错误是什么,比较好。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这属于checked exception必须要检查的。。。其他地方没写好么
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
sleep线程 调用interupt了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询