Hu, ZhangHao wrote:
> Hi All
> 
>  
> 
> I am using commons-dbcp-1.2.2 + common-pools-1.5.2 and meet a dead-lock
> problem.
> 
> The problem is if all connections in the thread pool are occupied, and
> other threads are waiting for db connection.
> 
> Then if those threads received InterruptedException, then the thread
> pool will be dead and can't be used any more.
> 
>  
> 
> But commons-dbcp-1.2.2 + common-pools-1.4 can work will with same
> setting and same test program.
> 
> The new version can't work properly with commons-dbcp-1.2.2? (I also try
> commons-dbcp-1.4 + common-pools-1.5.2, it can't work too...)
> 
> Any suggestions are appreciated.
> 

Thank you for reporting this. Unfortunately, this looks like a pool
bug.  It is being tracked as POOL-162 in JIRA
(https://issues.apache.org/jira/browse/POOL-162).  The only
workaround that I can suggest immediately is to avoid interrupting
threads blocked waiting on the pool, possibly using a positive
maxWait value as an alternative means of controlling blocked waits.

Comments on the ticket are welcome.  The fix looks simple.  Assuming
I am right on this, we should get this patched ASAP.


Phil
>  
> 
> The configuration for dbcp is as follow:
> 
> dal.connectionProperties=autoReconnect=true;
> 
> dal.initialSize=0
> 
> dal.maxActive=1
> 
> dal.maxIdle=1
> 
> dal.minIdle=0
> 
> dal.maxWait=-1
> 
> dal.validationQuery=select 1
> 
> dal.testOnBorrow=true
> 
> dal.testOnReturn=false
> 
> dal.testWhileIdle=true
> 
> dal.timeBetweenEvictionRunsMillis=60000
> 
> dal.numTestsPerEvictionRun=3
> 
> dal.minEvictableIdleTimeMillis=60000
> 
> dal.poolPreparedStatements=true
> 
> dal.maxOpenPreparedStatements=20
> 
>  
> 
> The test program is as follow:
> 
>  
> 
> package db.test;
> 
>  
> 
> import java.util.List;
> 
> import com.telenav.dal.content.verse.crawler.ISiteDefinition;
> 
> import com.telenav.dal.content.verse.crawler.PageCrawlTaskDao;
> 
> import com.telenav.dal.content.verse.crawler.SiteDefinitionDao;
> 
>  
> 
> public class TestConnection {
> 
>     public static void main(String[] args) throws Exception {
> 
>         Runnable t1 = new Runnable() {
> 
>             @Override
> 
>             public void run() {
> 
>                 int cnt = 0;
> 
>                 try {
> 
>                     cnt =
> PageCrawlTaskDao.getInstance().getCountAllPageTask(1);  // a
> time-consuming db operation, it will occupy the connection for some time
> 
>                 }
> 
>                 catch ( Exception e ) {
> 
>  
> System.out.println("------------------------------------------------");
> 
>                     e.printStackTrace();
> 
>                 }
> 
>                 
> 
>                 System.out.println(cnt);
> 
>             } 
> 
>         };
> 
>         
> 
>         Runnable t2 = new Runnable() {
> 
>             @Override
> 
>             public void run() {
> 
>                 int cnt = 0;
> 
>                 try {
> 
>                     cnt =
> PageCrawlTaskDao.getInstance().getCountAllPageTask(1);
> 
>                 }
> 
>                 catch ( Exception e ) {
> 
>                     System.out.println("catch exception: " +
> Thread.currentThread().getName());
> 
>                     //e.printStackTrace();
> 
>                 }
> 
>                 
> 
>                 System.out.println("thread " +
> Thread.currentThread().getName() + " : " + cnt);
> 
>             } 
> 
>         };
> 
>         
> 
>         Thread tt1 = new Thread(t1);
> 
>         tt1.start();
> 
>         Thread.sleep(2000);
> 
>         tt1.interrupt();
> 
>         
> 
>         int i = 0;
> 
>         while ( i < 20 ) {
> 
>             Thread tt2 = new Thread(t2, Integer.toString(i));
> 
>             tt2.start();
> 
>             Thread.sleep(1000);
> 
>             if(i == 3) 
> 
>                 tt2.interrupt();
> 
>             i ++;
> 
>         }
> 
>         
> 
>         //tt1.interrupt();
> 
>         
> 
>         Thread.sleep(60000);
> 
>  
> System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
> 
>         
> 
>         List<ISiteDefinition> sites = null;
> 
>         while ( true ) {
> 
>             try {
> 
>                                // The main thread can't get any
> connection here.....
> 
>                 sites =
> SiteDefinitionDao.getInstance().getAllSiteDefinitions(); // a
> non-time-consuming db operation to show the db connection pool is
> correct to use
> 
>             }
> 
>             catch (Exception e ) {
> 
>                 e.printStackTrace();
> 
>             }
> 
>             
> 
>             if ( sites != null ) {
> 
>                 for ( ISiteDefinition site : sites ) {
> 
>                     System.out.println(site.getUrl());
> 
>                 }
> 
>             }
> 
>             Thread.sleep(5000);
> 
>         }
> 
>     }
> 
> }
> 
>  
> 
>  
> 
> Best wishes,
> 
> Hu Zhanghao
> 
>  
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to