Hi ,
I have a problem with multi threading calling with for loop.
I have those two and many other classes in one jar file but n 2 different packages.
When i execute the jar file first runs the Aclass, from where i try to run multi threads.
from the run() of the class RunTheGame i call many other classes which are in the same package.
Like you can see from the for loop is executed the threads.
The problem is that when the second thread starts the first one is stopped this happens for all the threads, more simply when a new thread starts the old one is dead.
It seams that liken the threads uses the classes called from run() of the class RunTheGame as non multi threaded.
It gives this error:
Java Code:
Exception in thread "Thread-0" java.lang.NullPointerException
at thePackage2.EClass.getWhiteRemaining(EClass.java:49)
at thePackage2.EClass.isFinal(DClass.java:84)
at thePackage2.Spiel.<init>(Cclass.java:76)
at thePackage2.RunTheGame.run(RunTheGame.java:198)
at java.lang.Thread.run(Thread.java:745)
all the above refereed classes are called from the from run() of the class RunTheGame .
Like i understand all the threads use those classes as non thread autonomous clases.
Java Code:
public class Aclass {
private static Thread t[];
public static void main(String[] args) throws IOException {
for (int Game = 0; Game< 10; Game++) {
t[Game] = new Thread(new thePackage2.RunTheGame(aplayer, bplayer, Name, ID , Pmach));
t[Game].start();
try {
Thread.sleep(1);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}
Java Code:
public class RunTheGame implements Runnable{
private String a,b,c,d,e;
public RunTheGame(String aa, String bb, String cc, String dd ,String ee) {
a=aa;
b=bb;
c=cc;
d=dd;
e=ee;
}
public void run(){
//from here i call many other classes from "thePackage2" package, and also i use many variable from this classes
}
}
Any idea
Thank you in advance
Ki_ha1984
No comments:
Post a Comment