19 December 2008

Beware of Mysql Connector/J thread unsafeness

This week I ran into the problem of strange NullPointerExceptions from Mysql Connector/J. It turns out that (and I probably already knew this but had opressed it) the connector is not thread safe. That is on java.sql.Connection object should only be used by one thread at a time.

I though I had found a bug and submitted a detailed bug report (http://bugs.mysql.com/bug.php?id=41628). The helpful crew a Mysql told me that it was supposed to work in a thread unsafe way.

So what is the story here? Well in a real production system is is always good to use a real Connection Pool. I've tried the c3p0 connection pool (http://sourceforge.net/projects/c3p0) and configured it to max 1 connection.

No comments:

Post a Comment