javaapache-commons-pool

Does multiple GenericKeyedObjectPools use the same eviction thread?


If I'm using more than one GenericKeyedObjectPool in an application with enabled asynchronous idle object eviction how many "idle object eviction" thread will run in the background?

Do multiple GenericKeyedObjectPools create only one eviction thread or do they create separate threads for every pool?


Solution

  • The current implementation (v1.6) uses a static timer, so in practice multiple pools use only one eviction thread. (Assuming that they are loaded into the same classloader.) You can check it with jstack, there is only one timer thread:

    "Timer-0" daemon prio=10 tid=0x7bce5000 nid=0x1ca5 in Object.wait() [0x7b23d000]
       java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0xa26c0fe8> (a java.util.TaskQueue)
        at java.util.TimerThread.mainLoop(Timer.java:509)
        - locked <0xa26c0fe8> (a java.util.TaskQueue)
        at java.util.TimerThread.run(Timer.java:462)
    
       Locked ownable synchronizers:
        - None