Header

  1. View current page

    정상혁의 수첩

Profile_img_60x60_08
195

Connection Pool

http://java-source.net/open-source/connection-pools

 

 

dbcp와 c3p0 커넥션 풀 유지하기 :: 2009/02/17 18:09

 

 

c3p0 - JDBC3 Connection and Statement Pooling

 

jsp DBCP pool 모니터링 페이지

 

<%@ page language="java" contentType="text/html; charset=EUC-KR" %>
<%@ page import="
    java.util.*,
    javax.naming.*,
    javax.sql.*,
    org.apache.commons.beanutils.*,
    org.apache.commons.dbcp.*"
%>
<%
 Context initContext = new InitialContext();
 DataSource ds   = (DataSource)initContext.lookup("jdbc/Sims");
 BasicDataSource bds = (BasicDataSource)ds;

 try {
    Map<Object,Object> desc = BeanUtils.describe(bds);
%>
<%=desc%>
<%
 } catch(Exception e) {
  out.println(e.toString());
 }
%>

 

DBCP

Race condition error : https://issues.apache.org/jira/browse/DBCP-270

The pool is initialized the first time one of the following methods is invoked: getConnection, setLogwriter, setLoginTimeout, getLoginTimeout, getLogWriter.

 

testOnBorrow

http://geroros.hajima.net/entry/iBatis에서-커낵션-에러-날-때

mysql "Communications link failure" 문제

장시간 미사용된 DBCP 커넥션의 단절현상

 

removeAbandoned

long connection의 경우 의도하지 않은 connection close 현상 발생 가능 

 

<bean id="masterDs" class="org.apache.commons.dbcp.BasicDataSource" />

        ...

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

        <property name="removeAbandonedTimeout" value="30" />

        ...

</bean>

 

 

if(abandonedConfig != null && abandonedConfig.getRemoveAbandoned())

    connectionPool = new AbandonedObjectPool(null, abandonedConfig);

else            

    connectionPool = new GenericObjectPool();

...

dataSource = new PoolingDataSource(connectionPool);

 

 

 

conn = (Connection)_pool.borrowObject();

 

 

 

if(config != null && config.getRemoveAbandoned() && getNumIdle() < 2 && getNumActive() > getMaxActive() - 3)

    removeAbandoned();

if(pc.getLastUsed() <= timeout && pc.getLastUsed() > 0L)

    remove.add(pc);

if(config == null || !config.getRemoveAbandoned())

    break MISSING_BLOCK_LABEL_54;

synchronized(trace)

{

    boolean foundObject = trace.remove(obj);

 

 

 

성능비교

 http://javatech.org/2007/11/c3p0-vs-dbcp-the-straight-dope/

 

History

Last edited on 02/18/2011 18:12 by benelog

Comments (0)

You must log in to leave a comment. Please sign in.