Microsoft KB Archive/894552

= 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 =

Article ID: 894552

Article Last Modified on 10/7/2005

-

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:

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   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 &quot;Applies to&quot; 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(&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 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 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;Query Timeout 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;Query timeout 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;Query Timeout 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; }   } } Note   represents the name of the computer that is running SQL Server 2000,   represents your user ID, and   represents your password.

