3 Replies Latest reply on Jan 9, 2004 9:19 AM by Jean-MarcSpaggiari

    Clustering + Client Threads

    Paulo Henrique Newbie

      Hi everybody,

      I'm trying to use Clustering but I'm running into some problems. I use jboss-3.0.3 with tomcat-4.1.12 and the default configuration for clistering and farming. I'm using HA-JNDI as well.

      What I'm doing:

      Just after I call the create() of my EJB (Stateless Session EJB), I start several threads, each one calling once the remote method of the EJB. I mean: 1 call to create() then several calls to remoteMethod() in separate threads.


      The problem is:

      When I do it from a standalone Java client for the EJB, it works fine and I can see the RoundRobin. But when I do it from a Servlet, only one JBoss server is called (the same that runs the Servlet), that is, the cluster doesn't work properly.

      Any idea why??? Is there a solution for this? (I can't use a standalone client)

      I'm sending some source code below...

      Thanks in advance!
      Regards,

      Paulo


      --------- Source Code ------------

      /**
      * Method that creates and calls the EJB
      */
      protected void runJob() throws Exception
      {
      ComparisonProcessSrvMgrHome testComparisonBean = null;

      //Look up home interface
      try {
      Properties p = new Properties();
      p.put(Context.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      p.put(Context.URL_PKG_PREFIXES,
      "jboss.naming:org.jnp.interfaces");
      p.put(Context.PROVIDER_URL,
      "schindler:1100,ubatuba:1100");

      InitialContext ctx = new InitialContext(p);

      Object objrefComparison = ctx.lookup("ejb/com/cpqd/billing/recon/business/services/comparison/ComparisonProcessSrvMgrBean");

      testComparisonBean = (ComparisonProcessSrvMgrHome) PortableRemoteObject.narrow(objrefComparison,ComparisonProcessSrvMgrHome.class);

      }
      catch (Exception e) {
      e.printStackTrace();
      }

      final ComparisonProcessSrvMgr comparisonBeanRemote =
      testComparisonBean.create();

      for (int i = 0; i < 100; i++) {

      final int count = i;

      new Thread() {
      public void run() {
      try {
      comparisonBeanRemote.businessMethod(count);
      }
      catch (Exception e) {
      e.printStackTrace();
      }
      }
      }.start();
      }
      }