Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-3705

Concurrency "feature" in FaceletCacheImpl

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 2.1.0
    • 2.1.12
    • General
    • None
    • All

    Description

      I'm implementing my own FaceletCache which is decorating org.apache.myfaces.view.facelets.impl.FaceletCacheImpl by adding my own caching policy. When I was studying the code I'm decorating, I noticed that scrictly speaking it was not behaving. The problem lies in this code snippet (and the same for metadata facelets):

      if (_refreshPeriod != NO_CACHE_DELAY)

      { Map<String, DefaultFacelet> newLoc = new HashMap<String, DefaultFacelet>(_facelets); newLoc.put(key, f); _facelets = newLoc; }

      First of all, multiple concurrent modifications of _facelets map may cause lost updates. Think what happens when thread one copies the hashmap, updates local copy but before it sets the reference, thread b does the same. One update is now lost. In reality, the number of concurrent threads and number of lost updates may be much larger. The second thing is that the new reference set to _facelets is not quaranteed to be visible to other threads due to missing synchronization. To prove my concerns, I created a small test bench which proved my doubts and was able to show both lost updates and visibility problem. When I modified the map to be ConcurrentHashMap and just used put-method all problems vanished. So instead of

      Map<String, DefaultFacelet> newLoc = new HashMap<String, DefaultFacelet>(_facelets);
      newLoc.put(key, f);
      _facelets = newLoc;

      I used

      _facelets.put( key,f );

      I know it may not be a problem, possibly just causing multiple loads of same resource, but still I don't feel comfortable with the code behaving concurrency-wise incorrectly.

      BR, Paci

      Attachments

        Issue Links

          Activity

            People

              lu4242 Leonardo Uribe
              paci Pasi Salminen
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 1h
                  1h
                  Remaining:
                  Remaining Estimate - 1h
                  1h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified