Druid Connection Pool A set of murders caused by

Source: Internet
Author: User
Tags lua
Summary: Druid connection Pool A set of murders caused by

Run a batch update program on a very low machine today ~ ~ ~

Probably ran for 30 minutes ~ ~ ~ ~ this program ~ ~ ~ ~

Then the gorgeous newspaper is abnormal ~ ~ ~

The exact exception is this,

debug:  (basejdbclogger.java:132)     ooo using connection [ COM.ALIBABA.DRUID.PROXY.JDBC.CONNECTIONPROXYIMPL@4D4E22E1] [2014-07-17 15:19:35]5363945354 [ druid-connectionpool-destory-1422598563] com.alibaba.druid.pool.druiddatasource:1132  WARN :   (druiddatasource.java:1132)    get/close not same thread ERROR:  ( druiddatasource.java:1815)    abandon connection, open stacktrace          at java.lang.thread.getstacktrace (thread.java:1588) at  Com.alibaba.druid.pool.DruidDataSource.getConnectionDirect (druiddatasource.java:942) at  Com.alibaba.druid.filter.FilterChainImpl.dataSource_connect (filterchainimpl.java:4534) at  Com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection (statfilter.java:661) at  Com.alibaba.druid.filter.FilterChainImpl.dataSource_connect (filterchainimpl.java:4530) AT&NBsp;com.alibaba.druid.pool.druiddatasource.getconnection (druiddatasource.java:880) at  Com.alibaba.druid.pool.DruidDataSource.getConnection (druiddatasource.java:872) at  Com.alibaba.druid.pool.DruidDataSource.getConnection (druiddatasource.java:97)

This is the initial anomaly, and there's a large number of anomalies behind it,

caused by:java.sql.SQLException:connection holder is null at
	Com.alibaba.druid.pool.DruidPooledConnection.checkState (druidpooledconnection.java:1085) at
	Com.alibaba.druid.pool.DruidPooledConnection.getMetaData (druidpooledconnection.java:825) at
	Org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData (jdbcutils.java:285) ...
	More

Say what holder is empty

The first glimpse of Holder was like the source of spring, which was filled with holder (laughs)

But the holder here is not spirng, it's druid.

This holder is probably used to hou the connection inside the connection pool.

And why is it empty? The visual is which link is broken, or accidentally closed ...

    According to the exception-modulated source  at Com.alibaba.druid.pool.DruidDataSource.getConnectionDirect (Druiddatasource.java : 942)

941         if  (isremoveabandoned ())  {942                 StackTraceElement[] 
Stacktrace = thread.currentthread (). Getstacktrace (); 943                
Poolalbeconnection.setconnectstacktrace (StackTrace);                 
Poolalbeconnection.setconnectedtimenano ();                 

Poolalbeconnection.settraceenable (TRUE);                 synchronized   (activeconnections)  {                     activeconnections.put (poolalbEconnection, present);                 }              }

I don't see what's going on. Can only continue to see the log, or do not see what to

Then after looking at the code several times, the old feel isremoveabandoned () this method ghost.

To view the call:

Well, this destroyconnectionthread is very suspicious, jump

if (isremoveabandoned ()) {
removeabandoned ();
}

Go on

    public int removeabandoned ()  {      

  int removeCount = 0;

        long currrentnanos = system.nanotime ();         list<druidpooledconnection> abandonedlist =

 new ArrayList<DruidPooledConnection> ();         synchronized  (activeconnections)  {             iterator<druidpooledconnection> iter =

 activeconnections.keyset (). iterator ();             for  (;  iter.hasnext ();)  {                

Druidpooledconnection pooledconnection = iter.next ();                 if  (Pooledconnection.isrunning ())  {                   
  continue;                 }                  long timeMillis  =  (Currrentnanos - pooledconnection.getconnectedtimenano ())  /  (1000 * 1000)

;                 if  ( Timemillis >= removeabandonedtimeoutmillis)  {       
             iter.remove ();                      poOledconnection.settraceenable (FALSE);                   
  abandonedlist.add (pooledconnection);                 }              }         }   Slightly     }

Rub, this is not right, Timemillis >= Removeabandonedtimeoutmillis Timemillis This is the time when getconnection () was invoked

It means that after a connection is got, it's over removeabandonedtimeoutmillis so long I'll kill you.

And then keep looking for removeabandonedtimeoutmillis where this thing was set, and finally found out that it was in

<property name= "removeabandoned" value= "true"/>

<property name= "removeabandonedtimeout" value= "1800"/>

To initialize the configuration set here, the approximate meaning of these two parameters is that

The connection obtained through datasource.getconnontion () must call Close () within so many seconds of removeabandonedtimeout, or I will kill you. (that is, Conn cannot exceed the specified lease term)

And then tune it into 2 hours.

Then the program successfully ran out ~ ~ ~ Gorgeous 50 minutes.

Summarize:

Connection pool to prevent the program from getting a connection from the pool after forgetting to return the situation, and provided some parameters to set a lease, use this to some extent to prevent the connection leakage

    But if your business is really running for so long ~ ~ ~ Then pay attention to this setting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.