List:MySQL and Java« Previous MessageNext Message »
From:Mark Matthews Date:September 14 1999 7:16pm
Subject:Re: Interesting process problem
View as plain text  
Under Linux, every thread that is spawned shows up as a process under ps.

Are you closing your connections when you are done with them? If not, 
then they will not get closed until your application closes, and each 
connection takes a mysql thread to process.

Robust JDBC code takes the form of something like:

	//
	// Decalre all resources to be used
	//

	Connection Conn = null;
	Statement Stmt = null;
	ResultSet RS = null;

	try 
	{
		// Use connection. statement, and result set
	}
	catch (SomeException E)
	{
	}
	finally
	{
		if (RS != null)
		{
			try {RS.close();} catch (SQLException SQLE)
		}
		if (Stmt != null)
		{
			try {Stmt.close();} catch (SQLException SQLE)
		}
		if (Connection != null)
		{
			try {Conn.close();} catch (SQLException SQLE)
		}
	}

That way, no matter what happens in the processing of your code, the 
resources _always_ get reclaimed.

If you're running JDBC with servlets, you really should be looking into 
connection pooling mechanisms to reduce resource usage, and increase 
throughput in situations like yours.

	-Mark

On Tue, 14 Sep 1999 rmccown@stripped wrote:

> 
> Hi there.
>  Ive got an interesting problem happening here.  Im using java 1.2, Apache
> 1.3.x, and Linux 2.1.35.  Im writing a servlet, and using the following
> style of call to send a query:
> 
>    try {
>       Connection con = DriverManager.getConnection(SQL_DBURL); 
>       Statement stmt = con.createStatement();
>       String sQuery = "Select email, addrlist from users where userid='" +
> iUserID + "'";
>       ResultSet rs = stmt.executeQuery(sQuery);
>       if( rs.next() )
>       {
> 	...
> 
> what happens, is EVERY TIME that a request is executed, I get another
> process of mysql running.  here's the ps -auxw of one of the lines:
> 
> root   388  0.0  3.2  18976  1500  ?  S  N  14:33  0:00
> /usr/local/mysql-3.22.25-pc-linux-gnu-i686/bin/mysqld
> --basedir=/usr/local/mysql-3.22.25-pc-linux/gnu-i386
> --datadir=/usr/local/mysql/data --skip-locking --user=root
> --pid-file=/usr/local/mysql/data/goodolboys.pic
> --datadir=/usr/local/mysql/data
> 
> Over the span of a couple hours, I get hundreds of these, and eventually the
> machine grinds to a halt.
> 
> Any ideas?
> 
> -Bob
> 
>
> <><><><><><><><><><><><><><><><><><><><><><><>
> Bob McCown - Burst! Media LLC - (781) 852-5219
>
> <><><><><><><><><><><><><><><><><><><><><><><>
> 
> 
> 
Thread
Interesting process problemrmccown14 Sep
  • Re: Interesting process problemMark Matthews14 Sep
  • Re: Interesting process problemChristian Mack14 Sep