2 Replies Latest reply on Dec 17, 2013 6:08 AM by Jesper Pedersen

    Reducing the work during a coarse lock.

    Jeremy Whiting Expert

      Hi,

      Both I and members in my team are interested to know what can be moved outside of a coarse synchronized block in the IJ codebase. It is in the returnConnection method for a managed connection pool. We are seeing a high amount of time spent blocked on the cls object.

       

      ironjacamar/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/SemaphoreArrayListManagedConnectionPool.jav…

       

      There are a number of things that we would like to move outside the synchronized block. Here is a list of suggestions (not all my own):

       

      1. checking the state of the connection listener and the outcome deturmining the state of the variable 'kill'. line 446-447
      2. wrap the call to statistics.setInUsedCount with an if statement checking whether statistics is true. It is known that a call to statistics.setInUsedCount contains inside it the same check but, by then 3 method calls have been made. Whereas only 1 needs calling using the wrapping. It's not much but everything counts in this large block of code. L450
      3. move the modification of the two permits references, L 483-487
      4. move the call to used(), L 472

       

      and this simple optimization:

      1. remove the check for the key in the collection, instead try removing the object and checking the method return value. If not null then release the permit. L 483-487

       

      For each mentioned relocation of code, how much is necessary for the code to remain correct ?

       

      Jeremy

        • 1. Re: Reducing the work during a coarse lock.
          Jesper Pedersen Master

          checking the state of the connection listener and the outcome deturmining the state of the variable 'kill'. line 446-447

          Yeah, that can be moved outside.

          wrap the call to statistics.setInUsedCount with an if statement checking whether statistics is true. It is known that a call to statistics.setInUsedCount contains inside it the same check but, by then 3 method calls have been made. Whereas only 1 needs calling using the wrapping. It's not much but everything counts in this large block of code. L450

          Yeah, and it can be moved outside.

          move the modification of the two permits references, L 483-487

          Yeah, modifying the permit outside of the block is ok.

          move the call to used(), L 472

          Nope, that needs to happen due to the XAResource timeout reset.

          remove the check for the key in the collection, instead try removing the object and checking the method return value. If not null then release the permit. L 483-487

          Yeah.

          • 2. Re: Reducing the work during a coarse lock.
            Jesper Pedersen Master

            The changes has been merged.