Condition: Max connection pool size 10
and running 10 threads each invoking different MasterControllerEJB APIs. All of these APIs fetch a connection from the connection pool. Hence we used up 10 connection. At this point if any one of these threads need to get a new sequence ID from the database, we need another connection. But we can not get this connection as all the connections from the application server pool are exhausted. So this thread will continue to wait here. But as this method to get the ID is a synchronized block on a HashMap, all other threads will continue to wait for the lock on the HashMap to be released and that will never happen. So we are in a deadlock.

synchronized(hashmap) {

    get some value from the hashmap;

    if value meets some codition get a connection from the application server pool;

    use this connection to update some table in database and reload the hashmap;

}

Solution: If you have n threads, always set your minimum connection pool size to n + 2 or higher.

Exploring: java.util.concurrent.atomic.AtomicInteger

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed

This blog copyright 2009 by parijatkar