db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1027552 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/services/i18n/MessageService.java impl/services/monitor/BaseMonitor.java impl/services/monitor/FileMonitor.java
Date Tue, 26 Oct 2010 13:42:53 GMT
Author: kahatlen
Date: Tue Oct 26 13:42:52 2010
New Revision: 1027552

URL: http://svn.apache.org/viewvc?rev=1027552&view=rev
Log:
DERBY-1439: Remove the AntiGC thread

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i18n/MessageService.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/FileMonitor.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i18n/MessageService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i18n/MessageService.java?rev=1027552&r1=1027551&r2=1027552&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i18n/MessageService.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i18n/MessageService.java
Tue Oct 26 13:42:52 2010
@@ -57,12 +57,8 @@ public final class MessageService {
 	}
 
 
-	public static Object setFinder(BundleFinder theFinder) {
+	public static void setFinder(BundleFinder theFinder) {
 		finder = theFinder;
-
-		// Return an object for a caller to hang onto so
-		// Garbage collection doesn't GC this class.
-		return new MessageService().getClass();
 	}
 
 	public static String getTextMessage(String messageID) {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java?rev=1027552&r1=1027551&r2=1027552&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
Tue Oct 26 13:42:52 2010
@@ -88,9 +88,6 @@ import java.util.NoSuchElementException;
 
 import java.lang.reflect.InvocationTargetException;
 
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
 import java.net.URL;
 
 /**
@@ -134,9 +131,6 @@ abstract class BaseMonitor
 
 	ThreadGroup daemonGroup;
 
-	// anti GC stuff
-	AntiGC dontGC;
-
 	// class registry
 /* one byte  format identifiers never used
 	private InstanceGetter[]	rc1;
@@ -213,12 +207,6 @@ abstract class BaseMonitor
 		Monitor.getStream().println(LINE);
 		((TopService) services.elementAt(0)).shutdown();
 
-		synchronized (dontGC) {
-
-			dontGC.goAway = true;
-			dontGC.notifyAll();
-		}
-
 		ContextService.stop();
 		Monitor.clearMonitor();
 	}
@@ -265,39 +253,7 @@ abstract class BaseMonitor
 		if (!Monitor.setMonitor(this))
 			return;
 
-		Object msgService = MessageService.setFinder(this);
-
-		// start a backgorund thread which keeps a reference to this
-		// this monitor, and an instance of the Monitor class to ensure
-		// that the monitor instance and the class is not garbage collected
-		// See Sun's bug 4057924 in Java Developer Section 97/08/06
-
-		Object[] keepItems = new Object[3];
-		keepItems[0] = this;
-		keepItems[1] = new Monitor();
-		keepItems[2] = msgService;
-		dontGC = new AntiGC(keepItems);
-
-		final Thread dontGCthread = getDaemonThread(dontGC, "antiGC", true);
-		// DERBY-3745.  setContextClassLoader for thread to null to avoid
-		// leaking class loaders.
-		try {
-            AccessController.doPrivileged(
-            new PrivilegedAction() {
-                public Object run()  {
-                    
-                    dontGCthread.setContextClassLoader(null);
-                    return null;
-                }
-            });
-        } catch (SecurityException se1) {
-            // ignore security exception.  Earlier versions of Derby, before the 
-            // DERBY-3745 fix did not require setContextClassloader permissions.
-            // We may leak class loaders if we are not able to set this, but 
-            // cannot just fail.
-        }
-
-		dontGCthread.start();
+		MessageService.setFinder(this);
 
 		if (SanityManager.DEBUG) {
 			reportOn = Boolean.valueOf(PropertyUtil.getSystemProperty("derby.monitor.verbose")).booleanValue();
@@ -2202,26 +2158,3 @@ nextModule:
         }
     } // end of class ProviderEnumeration
 } // end of class BaseMonitor
-
-class AntiGC implements Runnable {
-
-	boolean goAway;
-	private Object keep1;
-
-	AntiGC(Object a) {
-		keep1 = a;
-	}
-
-	public void run() {
-		while (true) {
-			synchronized (this) {
-				if (goAway)
-					return;
-				try {
-					wait();
-				} catch (InterruptedException ie) {
-				}
-			}
-		}
-	}
-} // end of class AntiGC

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/FileMonitor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/FileMonitor.java?rev=1027552&r1=1027551&r2=1027552&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/FileMonitor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/FileMonitor.java
Tue Oct 26 13:42:52 2010
@@ -77,7 +77,23 @@ public final class FileMonitor extends B
 		return home;
 	}
 
-
+    /**
+     * Create a ThreadGroup and set the daemon property to make sure
+     * the group is destroyed and garbage collected when all its
+     * members have finished (i.e., either when the driver is
+     * unloaded, or when the last database is shut down).
+     */
+    private static ThreadGroup createDaemonGroup() {
+        try {
+            ThreadGroup group = new ThreadGroup("derby.daemons");
+            group.setDaemon(true);
+            return group;
+        } catch (SecurityException se) {
+            // In case of a lacking privilege, silently return null and let
+            // the daemon threads be created in the default thread group.
+            return null;
+        }
+    }
 
 	/**
 		SECURITY WARNING.
@@ -91,15 +107,7 @@ public final class FileMonitor extends B
 	private boolean PBinitialize(boolean lite)
 	{
 		if (!lite) {
-			try {
-				// Create a ThreadGroup and set the daemon property to
-				// make sure the group is destroyed and garbage
-				// collected when all its members have finished (i.e.,
-				// when the driver is unloaded).
-				daemonGroup = new ThreadGroup("derby.daemons");
-				daemonGroup.setDaemon(true);
-			} catch (SecurityException se) {
-			}
+            daemonGroup = createDaemonGroup();
 		}
 
 		InputStream versionStream = getClass().getResourceAsStream(ProductGenusNames.DBMS_INFO);
@@ -279,7 +287,23 @@ public final class FileMonitor extends B
 			// SECURITY PERMISSION - OP1
 			return PBgetJVMProperty(key3);
 		case 4:
-			return super.getDaemonThread(task, key3, intValue != 0);
+        {
+            boolean setMinPriority = (intValue != 0);
+            try {
+                return super.getDaemonThread(task, key3, setMinPriority);
+            } catch (IllegalThreadStateException e) {
+                // We may get an IllegalThreadStateException if all the
+                // previously running daemon threads have completed and the
+                // daemon group has been automatically destroyed. If that's
+                // what has happened, create a new daemon group and try again.
+                if (daemonGroup != null && daemonGroup.isDestroyed()) {
+                    daemonGroup = createDaemonGroup();
+                    return super.getDaemonThread(task, key3, setMinPriority);
+                } else {
+                    throw e;
+                }
+            }
+        }
 		case 5:
 			super.setThreadPriority(intValue);
 			return null;



Mime
View raw message