Richard O. Hammer wrote:
In my mailserver (a cousin of James) I use one java.sql.Connection throughout the life of the server. I call java.sql.DriverManager.getConnection() once at server startup. I've never suspected there was anything wrong with this, but I guess there might be.

If this is of interest to anybody, several times I have gotten "java.net.SocketException Connection reset by peer", indicating a dead connection to the database and requiring me to restart the server. This happens several hours after server startup, when I am running the mailserver in a Windows 2000 desktop and the database (PostgreSQL) in a RH7.3 Linux box on the LAN. I have found that I can work around this by running both mailserver and database on the same Linux box; then the Connection seems to last forever.

I generally don't critique design patterns (let he who is without bad design patterns cast the first stone), but permanently holding a single database connection open is a Bad Idea(tm). Some downsides:
- your code is inherently single-threaded.
- if you change to make it 1 thread = 1 db connection, you have a lot of unnecessarily open db connections.
- if you restart your db server, you get a failure in your app.
- if you have a network failure, you get a failure in your app.


Your scenario of putting the mail server and database on the same box addresses the fourth point. Database connection pools are pretty prevalent, even most JDBC3 drivers have something bundled. I would really encourage you to look into using one.

--
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to