multithreading issue

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

multithreading issue

Jérôme Saada
Hi,

here is my simple multithread example:

/import java.lang.Thread;

public class Sender extends Thread
{
  String message;
  int sleeper;
 
  public void Sender(String message,int sleeper){
    this.message=message;
    this.sleeper=sleeper;
    System.out.println("in init() -" + message + "- starting thread.");
    }

  public void run(){
      int i=0;
      for(;;){
          i++;
          System.out.println("[" + i + "]At " + this.message + " and
counting!");
          try {Thread.sleep(200 *this.sleeper);}
          catch (Exception e ) {
          println(e);
      }
        }
    }
   
    public static void main(String[] args){
        new Sender("hello",5).start();
        new Sender("world",10).start();
    }
}/


*When i run this on windows, it works:*

in init() -hello- starting thread.
in init() -world- starting thread.
[1]At hello and counting!
[1]At world and counting!
[2]At hello and counting!
[2]At world and counting!
[3]At hello and counting!
[4]At hello and counting!
[3]At world and counting!
[5]At hello and counting!
[6]At hello and counting!

*But under unix, only the first thread can be launched !* :
 java -classpath ./bsh.jar:. bsh.Interpreter launch.bsh
in init() -hello- starting thread.
in init() -world- starting thread.
Exception in thread "Thread-2" java.lang.ClassCastException:
bsh/BSHPrimaryExpression
   at bsh.BSHVariableDeclarator.eval (Unknown Source)
   at bsh.BSHTypedVariableDeclaration.eval (Unknown Source)
   at bsh.BSHBlock.evalBlock (Unknown Source)
   at bsh.BSHBlock.eval (Unknown Source)
   at bsh.BshMethod.invokeImpl (Unknown Source)
   at bsh.BshMethod.invoke (Unknown Source)
   at bsh.BshMethod.invoke (Unknown Source)
   at bsh.This.invokeMethod (Unknown Source)
   at Sender.run (BeanShell Generated via ASM (www.objectweb.org))
[1]At hello and counting!
[2]At hello and counting!
[3]At hello and counting!


Could you please tell me where i m wrong ?

Best regards



--


**

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users