title: NullPointerException when calling session bean from Thread
body: <p>I have some problem with my simple exercise program. I want to call a session bean from thread but it become NullPointer exception! but if I call it from a main thread it can run normally</p>
  
  <p>this is warning and exception </p>
  
  <pre><code>Warning: C:\Documents andSettings\User\MyDocuments\NetBeansProjects\ThreadCounter\dist\gfdeploy\ThreadCounter does not exist.
  Exception in thread "Thread-2" java.lang.NullPointerException
  at threadcounter.Main.run(Main.java:14)
  at java.lang.Thread.run(Thread.java:744)
  </code></pre>
  
  <p>This is runnable class which calling remote session bean</p>
  
  <pre><code>package threadcounter;
  
  import javax.ejb.EJB;
  import mysessionbean.CounterSessionBeanRemote;
  
  public class Main implements Runnable {
  @EJB
  private static CounterSessionBeanRemote counterSessionBean;
  
  @Override
  public void run() {
   System.out.println("counter : "+counterSessionBean.getCounter());  //NullPointer
    } 
  }
  </code></pre>
  
  <p>this is my main function </p>
  
  <pre><code>package threadcounter;
  
  public  class Ya {
  
  public static void main(String[] args){
  Main t1 = new Main();
  new Thread(t1).start();
    }
  
  }
  </code></pre>
  
  <p>and this is session bean</p>
  
  <pre><code>package mysessionbean;
  
  import java.util.Random;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.ejb.Stateless;
  
  @Stateless
  public class CounterSessionBean implements CounterSessionBeanRemote {
  private int counter = 0;
  
  @Override
  public int getCounter() {
      int temp = counter;
      temp++;
      Random r = new Random();
      try {
      Thread.sleep(r.nextInt(20));
      } catch (InterruptedException ex) {
      Logger.getLogger(CounterSessionBean.class.getName()).log(Level.SEVERE, null, ex);
      }
      counter = temp;
      return counter;
  }
  
  
  }
  </code></pre>