Why does an IllegalThreadStateException occur when Thread.start is called again

后端 未结 7 1747
攒了一身酷
攒了一身酷 2020-12-01 16:15
public class SieveGenerator{

static int N = 50;
public static void main(String args[]){

    int cores = Runtime.getRuntime().availableProcessors();

    int f[] =          


        
7条回答
  •  臣服心动
    2020-12-01 16:53

    * It is never legal to start a thread more than once.
    * In particular, a thread may not be restarted once it has completed
    * execution.
    *
    * @exception IllegalThreadStateException  if the thread was already started
    */
    public synchronized void start() {
    

    In Android, document still mention that we will get IllegalThreadStateException if the thread was already started.
    However for some device it will not throw this exception (tested on Kyocera 7.0). In some popular device like Samsung, HTC, it throw throw the exception normally

    I answer here because the Android question is mark as duplicated to this question.

提交回复
热议问题