'커넥션풀'에 해당되는 글 1건

  1. 2009.01.16 [DataBase] Connection Pool

[DataBase] Connection Pool

DB 2009. 1. 16. 15:19

jdbc 방식의 연결시에는 초기 지연시간 발생하기 때문에 서비스 시간이 지연 → 서비스 시간 개선 → connection을 DB에 미리 연동해두고 필요한 클라이언트에게 연결된 connection을 제공 → 메모리 부하

JNDI(Java Naming & Directory Interface) : JVM → CP
DBCP를 찾아 가기 위한 객체
Context ct = new InitialContext();
DataSource ds = (DataSorce)ct.lookup("java:comp/env/jdbc/등록한 이름");
Connection con = ds.getConnection();

이후는 JDBC와 동일하다.

* DBCP설정
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html

0. Drivers for older Oracle versions may be distributed as *.zip files rather than *.jar files. Tomcat will only use *.jar files installed in $CATALINA_HOME/common/lib. Therefore classes111.zip or classes12.zip will need to be renamed with a .jar extension. Since jarfiles are zipfiles, there is no need to unzip and jar these files - a simple rename will suffice

1.context configuration
server.xml의 context부분에 추가해준다.

<Resource name="jdbc/myoracle" -- context의 lookup에서 찾아갈 이름, myoracle만 변경가능, 대소문자 주의
              auth="Container"
              type="javax.sql.DataSource"
              driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"
              username="scott" 
              password="tiger"
              maxActive="50" -- 확장 커넥션의 생성 갯수, 기본과 동일하거나 기본+10
              maxIdle="40" -- 기본 커넥션의 생성 갯수
              maxWait="-1" -- 대기시간
/>

2. web.xml configuration
일반 클래스(DAO)에서 connection pool을 쓰려면 servlet이나 JSP에서 클래스를 인스턴스화 해서 쓴다.
안되면 web.xml설정, DTD의 설정에 따라 파일에 넣는다.
webcontent → WEB-INF → lib → web.xml
위에서 설정한 resource name으로 변경해준다

<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/myoracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

Posted by zeide
,