每个对象实例在start后在运行结束之前不能再次调用start启动,否则报错:
Exception in thread "main" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Thread.java:705)
很简单,在start方法第一行就是判断线程状态是否在运行中,否则直接抛出异常:
private volatile int threadStatus = 0; //not yet started
每个对象实例在start后在运行结束之前不能再次调用start启动,否则报错:
Exception in thread "main" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Thread.java:705)
很简单,在start方法第一行就是判断线程状态是否在运行中,否则直接抛出异常:
private volatile int threadStatus = 0; //not yet started
本文标题:一个对象实例只能start一个线程
本文链接:https://www.haomeiwen.com/subject/qpuisltx.html
网友评论