Click
  1. Click
  2. CLK-636

Replace EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap with java.util.concurrent.ConcurrentHashMap

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.2.0
    • Fix Version/s: 2.3.0-M1
    • Component/s: core
    • Labels:
      None

      Description

      Since Click required Java SDK 1.5 or later, we could leverage the java.util.concurrent.ConcurrentHashMap class to replace EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap class so reducing the Click runtime dependency.

      In my opinion here are some good reasons why:
      1. The ConcurrentHashMap class in Java SDK is more efficient since it utilizes internal hash classes to support better granularity and concurrency compare to simple syncrhonized on the instance like in DU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap.
      2. Looking at the use case ConcurrentReaderHashMap in Click, it used to cache the OGNL expression (please correct me if I am wrong). This scenario does not need exclusive lock on update which is the intended/ preferred use case for ConcurrentReaderHashMap. If there is a miss on OGNL expression on a name in the cache, it will cerate one and put it to the map if no other thread has not. So it will still perform as well as or better locking entire table. However, if we do need exclusive lock on update, we can simulate ConcurrentReaderHashMap with ConcurrentHashMap by setting concurrencyLevel to one.
      3. The ConcurrentHashMap support generic which is part of task being done to move Click code to Java generics.
      4. Looks like the EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap class is created by Doug Lea before contributions to java.util.concurrent packages in Java 1.5 SDK so the code may no longer optimized.

        Activity

        Hide
        Henry Saputra added a comment -

        If its ok, I could work on this and submit a patch.

        Show
        Henry Saputra added a comment - If its ok, I could work on this and submit a patch.
        Hide
        Malcolm Edgar added a comment -

        Hi Henry,

        I have tried this before and it caused strange object instantiation errors with Spring. I was not able to determine the underlying cause.

        regards Malcolm Edgar

        Show
        Malcolm Edgar added a comment - Hi Henry, I have tried this before and it caused strange object instantiation errors with Spring. I was not able to determine the underlying cause. regards Malcolm Edgar
        Hide
        Adrian A. added a comment -

        > I have tried this before and it caused strange object instantiation errors with Spring.
        > I was not able to determine the underlying cause.
        I was experiencing the same problems.

        Especially on WebSphere and Weblogic users complained about such problems, so we reverted back the patch.

        Show
        Adrian A. added a comment - > I have tried this before and it caused strange object instantiation errors with Spring. > I was not able to determine the underlying cause. I was experiencing the same problems. Especially on WebSphere and Weblogic users complained about such problems, so we reverted back the patch.
        Hide
        Henry Saputra added a comment -

        Hi Malcolm,

        I have tried to deploy the click-examples and looks like it run well. I also tried the spring security and able to create account.

        I dont see any custom bean/service in the spring xml file.

        Is there any other specific test/ example I could run to test with Spring?

        • Henry
        Show
        Henry Saputra added a comment - Hi Malcolm, I have tried to deploy the click-examples and looks like it run well. I also tried the spring security and able to create account. I dont see any custom bean/service in the spring xml file. Is there any other specific test/ example I could run to test with Spring? Henry
        Hide
        Joseph Schmidt added a comment -

        > I have tried to deploy the click-examples and looks like it run well. ...
        Henry,
        If you take a look at the Click history:
        http://click.apache.org/docs/roadmap-changes.html
        you will see that it's since 2005 (for the public) around, and so, there are many commercial applications that depend on it and it's stability.

        It's not that simple as just to change something and see if click-examples work .
        The base of Click applications in production is very very important and this is why backward compatibility and stability is key when considering updates to Click: many "cool" requests(even with patches) were refused because of this.

        Show
        Joseph Schmidt added a comment - > I have tried to deploy the click-examples and looks like it run well. ... Henry, If you take a look at the Click history: http://click.apache.org/docs/roadmap-changes.html you will see that it's since 2005 (for the public) around, and so, there are many commercial applications that depend on it and it's stability. It's not that simple as just to change something and see if click-examples work . The base of Click applications in production is very very important and this is why backward compatibility and stability is key when considering updates to Click: many "cool" requests(even with patches) were refused because of this.
        Hide
        Henry Saputra added a comment -

        Hi Joseph,

        This is not about coolness.

        Stability is important but since the project is no longer maintained moving from concurrentreaderhashmap to Java 5 ConcurrentHashMap class.

        I believe we need to move on to the latest Java standards like generics and modern packages like concurrency, especially there is no reason to stay using ConcurrentReaderHashMap.

        If you know good reason why switching wont work please let me know.

        • Henry
        Show
        Henry Saputra added a comment - Hi Joseph, This is not about coolness. Stability is important but since the project is no longer maintained moving from concurrentreaderhashmap to Java 5 ConcurrentHashMap class. I believe we need to move on to the latest Java standards like generics and modern packages like concurrency, especially there is no reason to stay using ConcurrentReaderHashMap. If you know good reason why switching wont work please let me know. Henry
        Hide
        Henry Saputra added a comment -

        Patch for replacing ConcurrentReaderHashMap with ConcurrentHashMap.

        Also contains changes to click/build/build.xml to remove this class from build-distribution target.

        Show
        Henry Saputra added a comment - Patch for replacing ConcurrentReaderHashMap with ConcurrentHashMap. Also contains changes to click/build/build.xml to remove this class from build-distribution target.
        Hide
        Malcolm Edgar added a comment -

        Hi Henry,

        The difficulty in applying this change is that I am not confident that it will not reintroduce the Spring errors we observed earlier. This error is difficult to quantify, does it only occur with certain Spring versions, with certain configurations and application JAR dependencies, does it relate the application server etc.

        regards Malcolm Edgar

        Show
        Malcolm Edgar added a comment - Hi Henry, The difficulty in applying this change is that I am not confident that it will not reintroduce the Spring errors we observed earlier. This error is difficult to quantify, does it only occur with certain Spring versions, with certain configurations and application JAR dependencies, does it relate the application server etc. regards Malcolm Edgar
        Hide
        Henry Saputra added a comment -

        We could simulate behavior of ConcurrentReaderHashMap with ConcurrentHashMap by setting concurrencyLevel to one.

        Malcolm, Adrian, do you have sample application that could replicate the weird instantiation error?

        I just think that this need to be fixed since Doug Lea (author of ConcurrentReaderHashMap) encourages users to move to Java 5 concurrency package with better lock and synchronization solution.

        Show
        Henry Saputra added a comment - We could simulate behavior of ConcurrentReaderHashMap with ConcurrentHashMap by setting concurrencyLevel to one. Malcolm, Adrian, do you have sample application that could replicate the weird instantiation error? I just think that this need to be fixed since Doug Lea (author of ConcurrentReaderHashMap) encourages users to move to Java 5 concurrency package with better lock and synchronization solution.
        Hide
        Henry Saputra added a comment -

        Actually the code in the PropertyUtils could still allow two threads could go in to call Map.get and both may return null so the operation will execute to override the value in the Map cache.

        I am proposing to change the Map instead of <String, Object> but to <String, Future>. Then the first thread call to Map.get will check if there exist task to get the cache value.

        If already exist just call get on it otherwise create one and by leveraging ConcurrentHashMap.putIfAbsent we could guarantee only one Future object exist for the String key.

        Show
        Henry Saputra added a comment - Actually the code in the PropertyUtils could still allow two threads could go in to call Map.get and both may return null so the operation will execute to override the value in the Map cache. I am proposing to change the Map instead of <String, Object> but to <String, Future>. Then the first thread call to Map.get will check if there exist task to get the cache value. If already exist just call get on it otherwise create one and by leveraging ConcurrentHashMap.putIfAbsent we could guarantee only one Future object exist for the String key.
        Hide
        Andrew Fink added a comment -

        +1 for ConcurrentHashMap

        >I have tried this before and it caused strange object instantiation errors with Spring. I was not able to determine the underlying cause.

        May be It was Spring bug (Click should support v2 and up)?

        Spring use ConcurrentHashMap internally.

        Since 3.0 their own wrapper is deprecated

        quote:

        • @deprecated as of Spring 3.0, since standard {@link java.util.concurrent.ConcurrentMap}
        • is available on Java 5+ anyway
        Show
        Andrew Fink added a comment - +1 for ConcurrentHashMap >I have tried this before and it caused strange object instantiation errors with Spring. I was not able to determine the underlying cause. May be It was Spring bug (Click should support v2 and up)? Spring use ConcurrentHashMap internally. Since 3.0 their own wrapper is deprecated quote: @deprecated as of Spring 3.0, since standard {@link java.util.concurrent.ConcurrentMap} is available on Java 5+ anyway
        Hide
        Malcolm Edgar added a comment -

        I appreciate the though around this issue but risk to production applications using various Spring version is too high for the reward of removing this class.

        regards Malcolm Edgar

        Show
        Malcolm Edgar added a comment - I appreciate the though around this issue but risk to production applications using various Spring version is too high for the reward of removing this class. regards Malcolm Edgar
        Hide
        Malcolm Edgar added a comment -

        Reopening issue for continuing analysis, will look at this in a future release.

        Show
        Malcolm Edgar added a comment - Reopening issue for continuing analysis, will look at this in a future release.
        Hide
        Bob Schellink added a comment -

        fixed in trunk

        Show
        Bob Schellink added a comment - fixed in trunk
        Hide
        Adrian A. added a comment -

        closing issue fixed a long time ago.

        Show
        Adrian A. added a comment - closing issue fixed a long time ago.

          People

          • Assignee:
            Bob Schellink
            Reporter:
            Henry Saputra
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development