5 Replies Latest reply on Jun 9, 2009 2:33 PM by lvdberg

    could not acquire lock

    ajanz
      sometimes i got following error message

      Caused by java.lang.IllegalStateException with message: "could not acquire lock on @Synchronized component: MyBean"

      code is

      @Stateful
      @Name("MyBean")
      @Scope(value = ScopeType.SESSION)
      public class MyClass implements MyBean{

      what is the problem? what can i do?
        • 1. Re: could not acquire lock
          lvdberg

          Sascha,


          could you provide some more information. It seems that you want to do something with MyBean on a session level. The reason you want a lock is that because of a using different winodws/frames or ajax requests?



          Leo

          • 2. Re: could not acquire lock
            sherkan777

            Sometimes I get same exception mostly on ajax requests to my SFSB.


            I've resolvet this by adding synchronisation to bean class.




            @Name("myBeanAction")
            @Scope(ScopeType.SESSION)
            @Synchronized(timeout=10000)



            • 3. Re: could not acquire lock
              lvdberg

              Although the Seam documentation states that aceesing session scoped components are protected from concurerent access, I've found that adding Ajax requests sometimes makes it a bit more complex than you think.


              You should try to solve this first at the source;  meaning add a queue to your pages and if that not sufficient or doesn't work, start synchronizing your beans. Especially run-time errors in synchronised beans can give you a lot of headaches (I found that out myself....)


              This is what I have in every page with forms/partial updates/rich components




              <a4j:queue requestDelay="500" sizeExceededBehavior="dropNew"
                             ignoreDupResponce="true" size="10" id="inputQueue" name="inputQueue" timeout="10000" /> 
              



              All a4j:support tags, push etc. refer to this queue. Works for me !


              Leo




              • 4. Re: could not acquire lock
                sherkan777

                Yes, this is right idea, also for


                 a4j:commandButton/a4j:form



                etc., try to add


                queue="queueName"



                .


                Use same queue name for each request to this one SFSB, but this exception can be thrown in pure Seam ajax request for js/Seam remoting.


                What about then? Only way is to catch concurrent requests by adding @Synchronised.


                see this:



                However, you can force a serialized threading model on any session bean or JavaBean component by adding the @Synchronized annotation.

                This concurrency model means that AJAX clients can safely use volatile session and conversational state, without the need for any special work on the part of the developer.

                • 5. Re: could not acquire lock
                  lvdberg

                  Hi Sherkan,


                  Off course you should add @Synchronized when you're using Seam remoting, but synchronizing your ajax page requests with a queue saves you a lot of additional problems. The browser is not really a multi-threding wonder and I personally find debugging client side requests not the most exiting part of my job. ;-)