相关疑难解决方法(0)

为什么再次调用Thread.start时会发生IllegalThreadStateException

public class SieveGenerator{

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

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

    int f[] = new int[N];

    //fill array with 0,1,2...f.length
    for(int j=0;j<f.length;j++){
        f[j]=j;
    }

    f[0]=0;f[1]=0;//eliminate these cases

    int p=2;

    removeNonPrime []t = new removeNonPrime[cores];

    for(int i = 0; i < cores; i++){
        t[i] = new removeNonPrime(f,p);
    }

    while(p <= (int)(Math.sqrt(N))){
        t[p%cores].start();//problem here because you cannot start a thread which has already started(IllegalThreadStateException)
        try{
            t[p%cores].join();
        }catch(Exception e){}
        //get the next prime
        p++;
        while(p<=(int)(Math.sqrt(N))&&f[p]==0)p++;
    }


    //count …
Run Code Online (Sandbox Code Playgroud)

java multithreading

15
推荐指数
1
解决办法
3万
查看次数

停止线程并再次开始在blackberry中提供IllegalThreadStateException

IllegalThreadStateException在使用以下代码时遇到异常:我已经启动了这个线程一次(通过使用thread.start())并再次尝试在另一个地方启动它,因此使用以下代码:

thread.interrupt();
thread.start();
Run Code Online (Sandbox Code Playgroud)

但是thread.start()扔了IllegalThreadStateException.

我应该用什么来解决它?

java multithreading blackberry java-me

11
推荐指数
2
解决办法
1万
查看次数

标签 统计

java ×2

multithreading ×2

blackberry ×1

java-me ×1