commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hu, ZhangHao" <zh...@telenav.cn>
Subject problem in commons-dbcp-1.2.2 + common-pools-1.5.2/1.5.4
Date Tue, 16 Mar 2010 09:13:56 GMT
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.

 

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

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message