2 Replies Latest reply on Oct 29, 2003 8:13 AM by Norton

    which thread should an EJB run in?

    Norton Newbie

      Hi,

      I have a question about how JBoss handles a threading situation. What I'm seeing doesn't seem to make sense.

      I'm running JBoss 3.0.6 on RH7.3. I have a servlet that spawns a bunch of threads to do some work. The servlet then waits for the threads to finish and then goes on. The worker threads call an EJB to do a db update after its processing.

      I've been printing out Thread.currentThread().getName() in each of the servlet and worker threads as well as in the EJB. It seems that the EJB that the worker threads are calling is running in the thread of the servlet. The result of this is that the EJB has to wait until the servlet wait loop (that waits for the finishing of the threads) finishes (via a timeout) before the EJB completes its work. This waiting, of course, hangs up the worker thread which doesn't complete until the servlet wait loop is done.

      I know that EJBs are running in each of the servlet threads in each servlet call, but how come an EJB doesn't run in a thread spawned by the code?

      Thanx in advance.

      Norton

        • 1. Re: which thread should an EJB run in?
          Ivan O. Parra Novice

          Please clarify your explanation.

          Let me get this straight, you have servlet A with Thread A that creates worker Threads X,Y,Z that all call different EJBs simultaneously. When you do a Thread.getCurrentThread().getName, you are getting the name of the Thread A?

          You should have 3 seperate transactions associated with X,Y,Z, respectively. Assuming that each transaction does not interfere with each other(via Pessimistically or DB Row locking), each thread should do their work independantly without knowledge of Thread A.


          >>I know that EJBs are running in each of the servlet threads in each servlet call, but how come an EJB doesn't run in a thread spawned by the code?

          What do you mean by "thread spawned by the code"? I guess you can force an RMI call by modifing the jndi.properties and setting a provider url.

          >>via a timeout
          Is this your timeout or a transaction rollback timeout?

          -Ivan

          • 2. Re: which thread should an EJB run in?
            Norton Newbie

            Yes, you have the situation straight. I don't believe any of the operations in the EJB are doing any blocking. But, as I said, the Thread.getCurrentThread().getName() call in the EJB is showing Thread A.

            You can ignore my "spawned by the code" comment. You got the gist of my problem and have basically told me that what I expect is what should happen. So any idea why it doesn't?

            The timeout is my own timeout.

            Thanx for your help and quick reply.

            Norton