6 Replies Latest reply on Mar 2, 2006 8:04 PM by anshah1

    Client blocks while accessing EJB on JBOSS ver4.0.3

    anshah1

      Hi,

      i have a client server environment set up and the server (EJB 2.0) version is 4.0.3SP1. Now I run into a situation here.

      Suppose I am logged in my client using a particular user and pswd, then I execute a task which takes a couple of minutes to run. This task is handled by a stateless SB, involves querying a web service for some data and then finally updating the database with retrieved value and displaying them to the user.

      Now if i try to log in again, using the same user and password but a new client instance, i do not get any exception thrown, however my client simply blocks and waits till my first task was completed.

      The moment my execution task is completed, my login goes through and i get access to my client environment.

      Also if I were to create two separate instances of my client environment and login using the same user, i can do that. That is to say that I can have two sessions for the same user operating simultaneously, but i am sure if i try to run any tasks, then they'll be blocked until the first executed one completes.

      I am quite confused with this operation. Also I am kind of a beginner in this regard.

      We need to get this problem sorted out soon, I appreciate any pointers or help in this matter.

      thanks,
      Anuj

        • 1. Re: Client blocks while accessing EJB on JBOSS ver4.0.3
          anshah1

          Hi,

          I believe I've found the problem, however not the solution yet. The problem has to do with a transaction that is initiated by a stateless SB. So here's the scenario.

          The client initiates a request for data retrieval from a remote web service API. This request is handled on the server side by a SLSB. The SLSB now queries the web service and retrieves data to put in the local database. It so happens that the web service retrieval takes a long time, more than the set transaction time and the session timeout. Now the jboss server tries either remove this bean or remove the transaction and things don't quite work out. It then creates a number of context lock messages and finally just hangs.

          So that's the problem. the solution to this would be to not use SLSB for these long running tasks. I've been googling this quite a bit and it seems there's something of a Work Manager API in the new jboss and that should be able to handle such tasks.

          My question now is a design question. What is the best way to handle a large computation or a large data retrieval task (whose time is going to be longer than either the session timeout or transaction timeout) using EJBs?

          Is JMS an option, a work manager api or something else? Also we can now move to something of this sort. Say a user initiates a request, we want to process it at our own time and return the results to the user at some time later. So this is kind of asynchronous.

          Please point me to the best solution for this problem in terms of design.

          Sincerely,
          Anuj

          • 2. Re: Client blocks while accessing EJB on JBOSS ver4.0.3
            persabi

            You might like to have a look at asynchronous proxy.

            http://docs.jboss.org/ejb3/app-server/tutorial/asynch/asynch.html

            • 3. Re: Client blocks while accessing EJB on JBOSS ver4.0.3
              anshah1

              Thanks for your reply, however this does not appear to be the right solution in my case.

              System.out.println("Waiting for asynbch invocation to complete");
              while (!future.isDone())
              {
              Thread.sleep(100);
              }
              ret = (String)future.get();


              This effectively means that the client is waiting for some response for the server, however in my case my client may simply log off and wish to come back later. The next time the client logs in, some form of UI tells the client
              "Welcome Mister, you task is now complete, you can retrieve your data by
              clicking here"


              thanks once again.
              Anuj






              • 4. Re: Client blocks while accessing EJB on JBOSS ver4.0.3
                persabi

                I think JMS is a good candidate for this.

                • 5. Re: Client blocks while accessing EJB on JBOSS ver4.0.3
                  anshah1

                  I guess you're right, I was reading a bit about JMS and think that it would work best for our situation. Thanks a lot for your help persabi.

                  I'll have more questions on MDB later. :))

                  Anuj

                  • 6. Re: Client blocks while accessing EJB on JBOSS ver4.0.3
                    anshah1

                    This post is for other ignorant people like me. Investigate the Service Activator design pattern for this problem.

                    --Anuj