1. Camel
  2. CAMEL-4345

Synchronized code causes long delays and hangs for big applications especially with Blueprint


    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.8.0
    • Fix Version/s: 2.8.2, 2.9.0
    • Component/s: camel-core
    • Labels:
    • Environment:

      Linux and Mac multicore machines

    • Patch Info:
      Patch Available
    • Estimated Complexity:


      The DefaultCamelContext uses synchronized "endpoints" which ends up ultimately extending a LinkedHashMap through the LRUCache. The LinkedHashMap is obviously not thread safe, so it requires synchronized guards when accessing the endpoints object. This especially happens in the getEndpoint(s) calls in the DefaultCamelContext. In large systems with lots of routes and on multicore systems, dynamically created routes (and many routes) can cause long delays and hang for long times since route creation and the starting of the camel route can occur in unison with synchronization. In a blueprint container, such as Karaf, this can cause timeouts on the bundle and camel routes will appear to hang indefinately. Thread dumps show the hangs occur on the synchronized call in getEndpoint(s). The fix for this is to use concurrent apis as much as possible and remove the synchronized code. I refactored the LRUCache/LRUSoftCache to use Google's ConcurrentLinkedHashMap (ASL2 License and removed the synchronized code that locks the endpoints object. This should remove the hangs since the locks are no longer required. Since COncurrentLinkedHashmap is not OSGi ready, I have shaded the classes in core. On my executions, all unit tests pass with this refactoring using the concurrent code. This should speed up Camel on multicore systems that have lots of routes.

      1. CAMEL-4345.patch
        15 kB
        Jeff Genender


        Jeff Genender created issue -
        Jeff Genender made changes -
        Field Original Value New Value
        Attachment CAMEL-4345.patch [ 12490756 ]
        Hadrian Zbarcea made changes -
        Assignee Hadrian Zbarcea [ hadrian ]
        Hadrian Zbarcea made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hadrian Zbarcea made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hadrian Zbarcea made changes -
        Fix Version/s 2.9.0 [ 12316374 ]
        Daniel Kulp made changes -
        Fix Version/s 2.8.2 [ 12317866 ]


          • Assignee:
            Hadrian Zbarcea
            Jeff Genender
          • Votes:
            0 Vote for this issue
            2 Start watching this issue


            • Created: