4 Replies Latest reply on Apr 23, 2002 10:37 AM by nickduong

    Start Separate Thread before Stateless Session Bean in JBoss

    nickduong

      Hi all,

      I'm having a problem trying to run a separate Thread before a stateless session bean is deployed.

      In JBoss 2.4.4, I use the following code:

      public class ProxyServerBean implements SessionBean {

      SessionContext sessionContext;
      static transient ProxyConnectionFactoryThread factoryThread = null;
      public ProxyServerBean() {}

      ........

      static {
      pooledSockets = new Hashtable();
      if (factoryThread == null) {
      factoryThread = new ProxyConnectionFactoryThread();
      factoryThread.start();
      debug("Started ProxyConnectionFactoryThread.");
      }
      }

      This code starts the separate thread fine. I also notice that if I put the static block in the constructor, it also work.

      However, in JBoss 3.0 beta and RC1 (w/ Catalina), the static block does not seem to execute on deployment of the EJB. Is there something in the jboss.xml or anything I can do to get the separate thread to run.

      Thanks!!!

      P.S.
      The reason for the separate thread is because the Thread contains a server socket listening port. I am running the listener socket in a thread, but if there is another way to run a listener (server) socket please let me know.

        • 1. Re: Start Separate Thread before Stateless Session Bean in J

          The spec doesn't permit you to do any of the following
          in an ejb:

          1) Start a new thread
          2) Accept a serversocket
          3) Have static data that is not final

          Perhaps you can explain what you are trying to do?

          Regards,
          Adrian

          • 2. Re: Start Separate Thread before Stateless Session Bean in J
            nickduong

            Adrain,

            Thanks again for the reply!!!!!!!!!

            Anyhow, here is the background on our project.

            We are trying to create a serversocket listening on the JBoss VM. The serversocket will listen for connections from our legacy database that only make socket connections. The legacy database will make 2 to 10 socket connections to the JBoss VM serversocket. The serversocket will create 2 to 10 sockets which will be pooled on a stateless session bean.

            Basically, we need to run a serversocket in the JBoss VM.

            Our plans were to run it in a separate thread.

            Its seems like JBoss 2.4.4, allowed us to start the thread in the session bean itself. Is this a mistake in JBoss implementation of the EJB 1.1 specs?

            Also is there a better way to do create a serversocket in JBoss?

            Thanks again!!!!!
            Nick

            • 3. Re: Start Separate Thread before Stateless Session Bean in J

              You have a database that opens connections on your app?
              That sounds the wrong way around?

              You will need some kind of client that takes the
              requests and calls the session bean.
              The client could run in the same VM as the session bean
              as a service with an MBean dependency on the ejb
              to ensure correct startup sequence. Because it is an
              Service MBean you can have lifecycle events like
              start() and stop().

              Regards,
              Adrian

              • 4. Re: Start Separate Thread before Stateless Session Bean in J
                nickduong

                Once again THANKS!!!!!!!!!!

                Actually the database we use is just many flat files. We don't have a "real" database. We run a program to read the files then open a connection to past along the data.

                Thank yo very much for your help!!!!

                Nick