db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1360137 - in /db/derby/code/trunk/java/drda/org/apache/derby/impl/drda: ClientThread.java DRDAConnThread.java NetworkServerControlImpl.java
Date Wed, 11 Jul 2012 12:12:00 GMT
Author: kahatlen
Date: Wed Jul 11 12:11:59 2012
New Revision: 1360137

URL: http://svn.apache.org/viewvc?rev=1360137&view=rev
Log:
DERBY-5847: Clean up IDE warnings in DRDAConnThread

Silence warning about possible leak of reference to "this" from
constructor.

Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java?rev=1360137&r1=1360136&r2=1360137&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java Wed Jul 11
12:11:59 2012
@@ -30,14 +30,12 @@ final class ClientThread extends Thread 
 	NetworkServerControlImpl parent;
 	ServerSocket serverSocket;
 	private int timeSlice;
-	private int connNum;
     
     ClientThread (NetworkServerControlImpl nsi, ServerSocket ss) {
-        
-        // Create a more meaningful name for this thread (but preserve its
-        // thread id from the default name).
-        NetworkServerControlImpl.setUniqueThreadName(this, "NetworkServerThread");
-        
+        // Use a more meaningful name for this thread.
+        super(NetworkServerControlImpl.getUniqueThreadName(
+                "NetworkServerThread"));
+
         parent=nsi;
         serverSocket=ss;
         timeSlice=nsi.getTimeSlice();

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=1360137&r1=1360136&r2=1360137&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Wed Jul 11
12:11:59 2012
@@ -233,12 +233,8 @@ class DRDAConnThread extends Thread {
 	DRDAConnThread(Session session, NetworkServerControlImpl server, 
 						  long timeSlice,
 						  boolean logConnections) {
-	
-   	super();
-
-		// Create a more meaningful name for this thread (but preserve its
-		// thread id from the default name).
-		NetworkServerControlImpl.setUniqueThreadName(this, "DRDAConnThread");
+        // Use a more meaningful name for this thread.
+        super(NetworkServerControlImpl.getUniqueThreadName("DRDAConnThread"));
 
 		this.session = session;
 		this.server = server;

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=1360137&r1=1360136&r2=1360137&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Wed Jul 11 12:11:59 2012
@@ -58,6 +58,7 @@ import java.util.Hashtable;
 import java.util.Properties;
 import java.util.StringTokenizer;
 import java.util.Vector;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.derby.drda.NetworkServerControl;
 import org.apache.derby.security.SystemPermission;
@@ -1479,39 +1480,23 @@ public final class NetworkServerControlI
         }		
 	}
 
-	/**
-	 * Set a thread name to be something that is both meaningful and unique (primarily
-	 * for debugging purposes).
-	 *
-     * The received thread's name is set to a new string of the form
-     *  [newName + "_n"], where 'n' is a unique thread id originally generated
-     *  by the jvm Thread constructor.  If the default name of the thread has
-     *  been changed before getting here, then nothing is done.
-     *
-	 * @param thrd An instance of a Thread object that still has its default
-	 *  thread name (as generated by the jvm Thread constructor).  This should
-	 *  always be of the form "Thread-N", where N is a unique thread id
-	 *  generated by the jvm.  Ex. "Thread-0", "Thread-1", etc.
-	 *
-	 **/
-	public static void setUniqueThreadName(Thread thrd, String newName) {
-
-		// First, pull off the unique thread id already found in thrd's default name;
-		// we do so by searching for the '-' character, and then counting everything
-		// after it as a N.
-		if (thrd.getName().indexOf("Thread-") == -1) {
-		// default name has been changed; don't do anything.
-			return;
-		}
-		else {
-			String oldName = thrd.getName();
-			thrd.setName(newName + "_" +
-			  oldName.substring(oldName.indexOf("-")+1, oldName.length()));
-		} // end else.
-
-		return;
+    /**
+     * Holds the sequence number to be assigned to the next thread that
+     * calls {@link #getUniqueThreadName(String)}.
+     */
+    private static final AtomicInteger nextThreadNumber = new AtomicInteger(1);
 
-	}
+    /**
+     * Get a thread name that is both meaningful and unique (primarily for
+     * debugging purposes).
+     *
+     * @param base the first part of the thread name (the meaningful part)
+     * @return a unique thread name that starts with {@code base} and is
+     * followed by an underscore and a unique sequence number
+     */
+    static String getUniqueThreadName(String base) {
+        return base + "_" + nextThreadNumber.getAndIncrement();
+    }
 
 	/*******************************************************************************/
 	/*        Protected methods                                                    */



Mime
View raw message