FIX: The SQL Server 2000 Driver for JDBC may spawn a new thread when you call the setQueryTimeout function on a connection object, and performance may decrease when you repeatedly call the setQueryTimeout function (894552)



The information in this article applies to:

  • Microsoft SQL Server 2000 Driver for JDBC

SYMPTOMS

Consider the following scenario. You call the setQueryTimeout method on a connection object that uses the Microsoft SQL Server 2000 Driver for JDBC. When you do this, the driver may spawn a new thread to monitor the query execution on the original connection. Additionally, when you repeatedly call the setQueryTimeout method in a high-load environment, performance may decrease. In this scenario, the system may run out of memory and crash.

RESOLUTION

A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next SQL Server 2000 Driver for JDBC service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
   Date         Time   Size     File name
   --------------------------------------------
   26-Jan-2005  18:29  287,007  Msbase.jar
   26-Jan-2005  18:29   67,167  Mssqlserver.jar
   26-Jan-2005  18:29   59,072  Msutil.jar
Note Because of file dependencies, the most recent hotfix or feature that contains these files may also contain additional files.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

To reproduce this problem, compile and run the following Java code sample:
import java.*;
import java.sql.*;
import java.util.*; 
import java.text.*;
import com.microsoft.jdbcx.sqlserver.SQLServerDataSource;

public class timeout_defect
{
	// Constructor
	public timeout_defect()
	{
	}

	public static void main(String[] args) throws Exception
	{
		Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

		int timeout=0;
		int displaytimeout=9999;

		ThreadGroup       group = null;
		Thread[]          threadList = null;
		int               activeThreads;
		int               numThreads;
		int               timeoutThreads = 0;

		//Connect to the SQL Server
		java.sql.Connection conn = null;
		try 
		{
			Properties p = new Properties();
			p.put("user", "<UserID>");
			p.put("password","<Password>");
			p.put("selectMethod", "direct");
			p.put("DatabaseName", "pubs");
			
			conn = java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://<Server>:1433", p);
			System.out.println("Connected to database.");
			System.out.println(" ");

			java.sql.Statement stmt1 = conn.createStatement();
			
			// Do not set Query Timeout (default to 0). 			
			System.out.println("Using default Query Timeout -- 0.");
			System.out.println(" ");

			//	timeout = 1;
			//	stmt1.setQueryTimeout(timeout);

			displaytimeout = stmt1.getQueryTimeout();

			System.out.println("Query Timeout set to  " + displaytimeout);
			System.out.println(" ");

			// Examine the threads.
			group = Thread.currentThread().getThreadGroup();
			activeThreads = group.activeCount();
			threadList = new Thread[activeThreads];
			numThreads = group.enumerate(threadList);

			for (int index = 0; index < numThreads; index++)
			{
				if (threadList[index].getName().equals("Connect Query Timeout-Thread"))
				{
					timeoutThreads++;
				}
			}
			System.out.println("Num Query Timeout threads: " + timeoutThreads);
			System.out.println(" ");

			stmt1.close();
			stmt1 = conn.createStatement();

			// Set the Query Timeout to 1.  			
			System.out.println("Setting query timeout to 1.");
			System.out.println(" ");
			timeout = 1;
			stmt1.setQueryTimeout(timeout);

			displaytimeout = stmt1.getQueryTimeout();

			System.out.println("Query timeout set to " + displaytimeout);
			System.out.println(" ");

			// Examine the threads.
			group = Thread.currentThread().getThreadGroup();
			activeThreads = group.activeCount();
			threadList = new Thread[activeThreads];
			numThreads = group.enumerate(threadList);

			for (int index = 0; index < numThreads; index++)
			{
				if (threadList[index].getName().equals("Connect Query Timeout-Thread"))
				{
					timeoutThreads++;
				}
			}
			System.out.println("Num Query Timeout threads: " + timeoutThreads);
			System.out.println(" ");

			stmt1.close();
			stmt1 = conn.createStatement();

			// Set the Query Timeout to 0  			
			System.out.println("Setting Query Timeout to 0.");
			System.out.println(" ");
			timeout = 0;
			stmt1.setQueryTimeout(timeout);

			displaytimeout = stmt1.getQueryTimeout();

			System.out.println("Query Timeout set to " + displaytimeout);
			System.out.println(" ");

			// Examine the threads.
			group = Thread.currentThread().getThreadGroup();
			activeThreads = group.activeCount();
			threadList = new Thread[activeThreads];
			numThreads = group.enumerate(threadList);

			for (int index = 0; index < numThreads; index++)
			{
				if (threadList[index].getName().equals("Connect Query Timeout-Thread"))
				{
					timeoutThreads++;
				}
			}
			System.out.println("Num Query Timeout threads: " + timeoutThreads);
			System.out.println(" ");

			stmt1.close();
		} 
		catch (java.sql.SQLException s) 
		{
			s.printStackTrace();
		}
		finally
		{
			// Cleanup
			if (conn!=null)
				conn.close();
			conn=null;
		}
	}
}
Note Server represents the name of the computer that is running SQL Server 2000, UserID represents your user ID, and Password represents your password.

REFERENCES

For more information about JDBC, click the following article number to view the article in the Microsoft Knowledge Base:

313100 How to get started with Microsoft JDBC

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates


Modification Type:MinorLast Reviewed:10/7/2005
Keywords:kbQFE kbfix kbbug KB894552 kbAudDeveloper kbAudITPRO