1 Reply Latest reply on Oct 27, 2008 12:05 PM by marcioendo.marcioendo.gmail.com

    static hsshMap with race condition issue

      hi every one


      i am using the static hashMap in my project for caching purpose.
      so i initialize the hashMap with the @Create method so statefull session bean with APPLICATION scope.
      so it get initialize at once at the begining.
      through the getter method of hashMap  i get the value for particular key.
      through the setter method of hashMap  i update the value for particular key.


      here i have the issue with hashMap race condition.
      the issue is in some time i am update the value of hashMap  in particular key.
      at the time of updating the value of hashMap  in particular key some one try to get he value for that  particular key from hashMap, so i got the null pointer exception.
      i thing the two threads are in race condition.
      after tant i cant get any value from the hash map.


      i try with synchronized blck and synchronized for both getter  and setter
      and slo itry with ConcurrentHashMap still i get the same exception .


      please any one help me to resolve this issue.


      by
      thiagu.m



        • 1. Re: static hsshMap with race condition issue
          marcioendo.marcioendo.gmail.com

          I don't think the problem is synchronization.


          SFSB are not meant to be used in the APPLICATION scope. Also, SFSB are designed to be single-client sort of speak.


          I would recommend one of the following:



          1. Implement a Seam POJO with APPLICATION scope.

          2. Use JBoss Cache (or any other cache implementation). Then you could use a stateless session bean as facade to that.

          3. If you are using JBAS, you can implement a @Service bean, which can be thought as singletons managed by the AS.