2 Replies Latest reply on Oct 18, 2007 2:39 AM by Oskar Carlstedt

    Multithreading in Jboss 4.0.1

    pran a Newbie


      We are trying to connect to a third party webservice to propagate the changes to the thirdparty system(in the suggeted JNDI look up pattern described in the jboss-webservice tutorial and it is working fine)

      Since the number of propagation updates are large,now we wanted to have parallel updates to the third party system,which is like having a master thread creaing few child threads,each will take,say 1000 records and updates in the 3rd party system using the webservices in parallel.

      Now,we are having an issue while using multiple threads.If I understand correctly,I guess the issue is because,we are sharing websevice client name registered in the JNDI,and it is giving exceptions.

      Has anyone have any idea of how can invoke multi threading with webservices.In the other way,we are trying to have multiple threads connecting the same webservice concurrently in the same appserver.

      we are using JBoss 4.0.1 and jdk 1.4

      Any suggestions would be appreciated.Following is the code snippet for conencting to webservices:

      private boolean connect() throws Exception
      Properties env = new Properties();
      env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client:org.jboss.naming");
      env.setProperty(Context.PROVIDER_URL, JNDI_URL);
      env.setProperty("j2ee.clientName", "nn-ws4ee-client");

      InitialContext iniCtx = new InitialContext(env);
      Service service = (Service)iniCtx.lookup(NN_CLIENT_JNDI_NAME);
      nrdInterface = (NRD)service.getPort(NRD.class);
      ((Stub)nrdInterface)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, url);
      isConnected = true;
      catch(Exception exc)
      logger.fatal("NN Client Wrapper initialization exception. " +
      "The JNDI may not be correctly configured as follows: JNDI Location: " + JNDI_URL +
      " NN Client JNDI Name: " + NN_CLIENT_JNDI_NAME);
      logger.fatal("NN Client Wrapper initialization exception:", exc);

      isConnected = false;
      throw exc;
      return isConnected;


        • 1. Re: Multithreading in Jboss 4.0.1
          pran a Newbie

          No one has encounted this?

          How abt Jboss team?


          • 2. Re: Multithreading in Jboss 4.0.1
            Oskar Carlstedt Novice


            The most correct way to do this is to write your own MBean/Service. AFAIK threads are not allowed inside an EJB (some application servers will allow threads in the EJB). So writing your own MBean that will take care of multithreading might solve your problem.

            Creating MBeans is about adding a new service entry in you jboss-app.xml that will point out a your-service.xml file.

            You MBean javacode must implement an interface s.a. YourServiceMBean (Notice the pattern interface name ends with MBean, the implementation does not);
            mbean interface: YourServiceMBean
            mbean impleementation: YourService

            You are looking up MBeans in the same way as you do with an EJB with the

            The MBean has some life cycle methods that you might want to use:
            start(), stop(), ... Start is called when the service is deployed. Check the JBoss application server documentation for more details.

            Hope this can help you.