검색해보자.
위키백과에 검색을 해보았다.
여기서 모르는 단어인 캐시가 나왔다. 검색해보자.
다시 커넥션풀로 돌아와 보자.
커넥션 풀을 지원하는 DBMS로는 위와 같이 있다고 한다.
한달 정도 MySQL을 사용했으니 나름 익숙해 졌다고 생각한다. MySQL의 Connection Pooling을 들어가보자.
😵😵😵😵 울렁 거리지만, 참고 읽어보자.
내 해석 : 커넥션 풀링은 기술이다. 풀을 생성하고 관리하는 // 사용하기로 준비되어 있는 // 어떤 쓰레드로 인해 // 그들을 필요로하는.
커넥션풀링은 매-우 향상시킨다. 자바 어플리케이션 퍼포먼스를, 전체 리소스 사용량을 줄이면서
번역기를 돌려보자.
연결 풀링은 연결 풀을 필요로 하는 스레드에서 사용할 수 있는 연결 풀을 만들고 관리하는 기술입니다. 연결 풀링은 전체 리소스 사용을 줄이면서 Java 응용프로그램의 성능을 크게 향상시킬 수 있습니다.
크게 다르지 않은 것 같다.
위의 내용을 해석했지만 내용이 많기도하고, 잘 와닿지 않아서 번역기를 돌렸다.
커넥션풀의 장점은 무엇일까?
커넥터/J와 연결 풀링 사용
아래와 같은 소스코드를 사용한다고 한다.
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class MyServletJspOrEjb {
public void doSomething() throws Exception {
/*
* Create a JNDI Initial context to be able to
* lookup the DataSource
*
* In production-level code, this should be cached as
* an instance or static variable, as it can
* be quite expensive to create a JNDI context.
*
* Note: This code only works when you are using servlets
* or EJBs in a J2EE application server. If you are
* using connection pooling in standalone Java code, you
* will have to create/configure datasources using whatever
* mechanisms your particular connection pooling library
* provides.
*/
InitialContext ctx = new InitialContext();
/*
* Lookup the DataSource, which will be backed by a pool
* that the application server provides. DataSource instances
* are also a good candidate for caching as an instance
* variable, as JNDI lookups can be expensive as well.
*/
DataSource ds =
(DataSource)ctx.lookup("java:comp/env/jdbc/MySQLDB");
/*
* The following code is what would actually be in your
* Servlet, JSP or EJB 'service' method...where you need
* to work with a JDBC connection.
*/
Connection conn = null;
Statement stmt = null;
try {
conn = ds.getConnection();
/*
* Now, use normal JDBC programming to work with
* MySQL, making sure to close each resource when you're
* finished with it, which permits the connection pool
* resources to be recovered as quickly as possible
*/
stmt = conn.createStatement();
stmt.execute("SOME SQL QUERY");
stmt.close();
stmt = null;
conn.close();
conn = null;
} finally {
/*
* close any jdbc instances here that weren't
* explicitly closed during normal code path, so
* that we don't 'leak' resources...
*/
if (stmt != null) {
try {
stmt.close();
} catch (sqlexception sqlex) {
// ignore, as we can't do anything about it here
}
stmt = null;
}
if (conn != null) {
try {
conn.close();
} catch (sqlexception sqlex) {
// ignore, as we can't do anything about it here
}
conn = null;
}
}
}
}
정리를 해보면, 데이터베이스 커넥션풀이란 애플리케이션에서 필요로 하는 시점에 커넥션을 만드는 것이 아니라 미리 일정한 수의 커넥션을 만들어 놓고 필요한 시점에 애플리케이션에 제공하는 서비스 및 관리 체계를 말한다.
더 알아볼 것: 어떻게 커넥션풀이 사용되는지..
참고 및 본글