java.lang.IllegalThreadStateException
2018-01-31 14:08
387 查看
这个问题的原因是:同一个Thread重复调用了start方法,如果你想开启多个线程,并且共享资源的时候,有两个方法
1.把共享资源设置为static
2.使用runnable
下面是一组上产上述错误原因的代码
1.把共享资源设置为static
2.使用runnable
下面是一组上产上述错误原因的代码
public class Test1 { public static void main(String[] args) { Thread thread = new Demo(); thread.start(); thread.start();//这里删掉就不会报IllegalThreadStateException异常 } } class Demo extends Thread{ int x = 0; @Override public void run() { while(true){ if(x>100){ System.out.println(x++); } } } }
相关文章推荐
- java.lang.IllegalThreadStateException问题解决
- Android多线程之java.lang.IllegalThreadStateException: Thread already started
- 单击事件开启线程时,再次单击就会出现 java.lang.IllegalThreadStateException: Thread already started. 错误
- 解决 java.lang.IllegalThreadStateException: Thread already started. 错误
- java.lang.IllegalThreadStateException: Thread already started.
- java.lang.IllegalThreadStateException异常原因解析
- java.lang.IllegalThreadStateException 线程运行报错
- Exception in thread "AWT-EventQueue-0" java.lang.IllegalThreadStateException
- java.lang.IllegalThreadStateException异常原因解析
- java.lang.IllegalThreadStateException异常原因解析——同一个线程不能重复调用start方法
- java.lang.IllegalThreadStateException: Thread already started.
- 解决 java.lang.IllegalThreadStateException: Thread already started. 错误
- java.lang.IllegalThreadStateException异常分析
- java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
- java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
- java.lang.IllegalStateException: Hardware acceleration can only be used with a single UI thread.
- java.lang.IllegalThreadStateException异常原因解析
- 同一个Thread启动第二次会报错java.lang.IllegalThreadStateException
- java.lang.IllegalThreadStateException
- java.lang.IllegalMonitorStateException: object not locked by thread before notify()