Microsoft KB Archive/899402

= FIX: You may experience a decrease in performance if you repeatedly call the setQueryTimeout method on a connection object by using the SQL Server 2000 Driver for JDBC =

Article ID: 899402

Article Last Modified on 10/11/2005

-

APPLIES TO


 * Microsoft SQL Server 2000 Driver for JDBC

-





SYMPTOMS
When you call the setQueryTimeout method on a connection object by using the Microsoft SQL Server 2000 Driver for JDBC, the JDBC driver will spawn a new thread to monitor the query execution on the original connection. If you repeatedly call the setQueryTimeout method in a high load environment, you may experience a decrease in performance and the behavior may eventually lead to an out-of-memory 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:

http://support.microsoft.com/contactus/?ws=support

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   Version   Size     File name -- 26-Jan-2005  11:29  2.2.0045  287,007  Msbase.jar 26-Jan-2005 11:29  2.2.0045   67,167  Mssqlserver.jar 26-Jan-2005 11:29  2.2.0045   59,072  Msutil.jar



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the behavior
Compile and then run the following Java code example. 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(&quot;com.microsoft.jdbc.sqlserver.SQLServerDriver&quot;);

int timeout=0; int displaytimeout=9999;

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

// Connect to the computer that is running SQL Server. java.sql.Connection conn = null; try {           Properties p = new Properties; p.put(&quot;user&quot;, &quot;&quot;); p.put(&quot;password&quot;,&quot;&quot;); p.put(&quot;selectMethod&quot;, &quot;direct&quot;); p.put(&quot;DatabaseName&quot;, &quot;pubs&quot;); conn = java.sql.DriverManager.getConnection(&quot;jdbc:microsoft:sqlserver://:1433&quot;, p); System.out.println(&quot;Connected to database.&quot;); System.out.println(&quot; &quot;);

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

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

displaytimeout = stmt1.getQueryTimeout;

System.out.println(&quot;Querytimeout set to &quot; + displaytimeout); System.out.println(&quot; &quot;);

// 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(&quot;Connect Query Timeout-Thread&quot;)) {                   timeoutThreads++; }           }            System.out.println(&quot;Num Query Timeout Threads: &quot; + timeoutThreads); System.out.println(&quot; &quot;);

stmt1.close; stmt1 = conn.createStatement;

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

displaytimeout = stmt1.getQueryTimeout;

System.out.println(&quot;Querytimeout set to &quot; + displaytimeout); System.out.println(&quot; &quot;);

// 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(&quot;Connect Query Timeout-Thread&quot;)) {                   timeoutThreads++; }           }            System.out.println(&quot;Num Query Timeout Threads: &quot; + timeoutThreads); System.out.println(&quot; &quot;);

stmt1.close; stmt1 = conn.createStatement;

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

displaytimeout = stmt1.getQueryTimeout;

System.out.println(&quot;Querytimeout set to &quot; + displaytimeout); System.out.println(&quot; &quot;);

// 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(&quot;Connect Query Timeout-Thread&quot;)) {                   timeoutThreads++; }           }            System.out.println(&quot;Num Query Timeout Threads: &quot; + timeoutThreads); System.out.println(&quot; &quot;);

stmt1.close; }        catch (java.sql.SQLException s)         { s.printStackTrace; }       finally {           // Cleanup if (conn!=null) conn.close; conn=null; }   }    public static Connection getConnection throws SQLException, ClassNotFoundException {       SQLServerDataSource ds = new SQLServerDataSource; ds.setServerName(&quot;&quot;); ds.setPortNumber(1433); ds.setUser(&quot;&quot;); ds.setPassword(&quot;&quot;); return ds.getConnection; } } Note In this code, replace,   , and   with the name of the computer that is running SQL Server, your user ID, and your password.

