title: Get Stateless Bean from InitialContext in different thread
body: <p>I want to call a stateless Session Bean Deployed in JBoss 7 from java desktop application.<br>
  I create InitialContext instance and everything is ok if I lookup and call bean methods in the same thread (bean1 in following code).<br>
  But if I get bean proxy from InitialContext in another thread, the program raises an Exception when I call a method from bean (bean2 in following Code).<br>
  Partial source code I use:</p>
  
  <pre><code>public class Tester1 implements Runnable
  {
      InitialContext ctx;
      static String beanAddr = "MobileSubscribersService_war_exploded/SubscriberEJB!com.persianswitch.ussd.ISubscriberBeanRemote";
  
      public void doIt()  throws NamingException
      {
          Properties p = new Properties();
          p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
          p.put(Context.PROVIDER_URL, "remote://localhost:4447");
          p.put(Context.SECURITY_PRINCIPAL, "user");
          p.put(Context.SECURITY_CREDENTIALS, "pass");
          p.put("jboss.naming.client.ejb.context", true);
          ctx = new InitialContext(p);
  
          ISubscriberBeanRemote bean1 =  (ISubscriberBeanRemote)ctx.lookup(beanAddr);
          int res = bean1.getLanguageByMobileNo("12345"); // this line runs good
  
          Thread th = new Thread(this);
          th.start();
      }
  
      @Override
      public void run() {
          try {
              ISubscriberBeanRemote bean2 = (ISubscriberBeanRemote)ctx.lookup(beanAddr);
              int res = bean2.getLanguageByMobileNo("12345"); // Throws Exception Here
          } catch (NamingException e) {
          }
      }
  }
  </code></pre>
  
  <p>Exception content:</p>
  
  <pre><code>Exception in thread "Thread-2" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:MobileSubscribersService_war_exploded,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@3337cdec
      at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
      at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
      at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
      at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
      at com.sun.proxy.$Proxy0.getLanguageByMobileNo(Unknown Source)
      at com.persianswitch.Tester1.run(Tester1.java:52)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>I want to reuse one InitialContext in multiple threads for improving performance.<br>
  Is there any mistake in my code? Are there any rule that I must know? </p>