Java

JDBC connector의 thread-safe 문제

휘사마 2011. 11. 26. 20:30
http://www.ibm.com/developerworks/java/library/j-threads3.html


For example, the JDBC Connection class is not thread-safe -- two threads cannot safely share a Connection at a fine level of granularity -- but if each thread had its own Connection, then multiple threads can safely perform database operations simultaneously.

JDBC의 Connection 클래스는 thread-safe 하지 않다고 한다.

그래서 각 쓰레드마다 커넥션을 소유하면 된다고 되어 있다.

밑에는 TLS 에 대한 이야기이고..



아니면 DAO를 singleton 으로 만들고

DAO에서 커넥션을 1개만 사용하면서 모든 메소드에 적절히 lock을 걸어도 될듯.