Results 1 to 4 of 4
  1. #1
    ki_ha1984 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    118
    Rep Power
    0

    Default Call multi threading with for loop - error

    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

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Call multi threading with for loop - error

    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)
    There was a null value at line 49. Look at the statement at line 49 and find the variable with the null value. Then backtrack and find out where the null value came from.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    ki_ha1984 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    118
    Rep Power
    0

    Default Re: Call multi threading with for loop - error

    Dear Norm,

    Thank you for your answer.

    I understand the message of the error, but my problem is that this error appears only when starts the next thread.
    If the processes run in series, the error does not appear.

    Is it ok the mufti threading that i use ?


    ki_ha1984

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Call multi threading with for loop - error

    Is it ok the mufti threading that i use ?
    I can not tell without testing.
    Can you make a small, complete program that compiles, executes and shows the problem?

    What was null on line 49? Why was it null?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Multi Threading
    By NajwaMy in forum New To Java
    Replies: 6
    Last Post: 08-15-2013, 03:16 PM
  2. Multi-Threading
    By TonyDaniels in forum New To Java
    Replies: 4
    Last Post: 03-09-2012, 06:16 PM
  3. Multi-Threading
    By TonyDaniels in forum Advanced Java
    Replies: 1
    Last Post: 03-09-2012, 05:52 PM
  4. Multi-threading issue
    By StevenTNorris in forum Advanced Java
    Replies: 2
    Last Post: 10-19-2011, 09:08 PM
  5. Problem in Multi threading.
    By Chetans in forum Advanced Java
    Replies: 3
    Last Post: 03-23-2010, 04:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •