8042327: Enhance thread contexts in serviceability
authorjbachorik
Fri, 01 Aug 2014 13:31:03 +0200
changeset 29921 f13586cdb0e4
parent 29920 f81c14f472ab
child 29922 7b9c1e1532cf
8042327: Enhance thread contexts in serviceability Reviewed-by: chegar, dfuchs, olagneau, sla
jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientCommunicatorAdmin.java
jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientNotifForwarder.java
jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ServerCommunicatorAdmin.java
jdk/src/java.management/share/classes/javax/management/monitor/Monitor.java
jdk/src/java.management/share/classes/sun/management/jdp/JdpController.java
--- a/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientCommunicatorAdmin.java	Thu Apr 02 11:43:11 2015 +0100
+++ b/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientCommunicatorAdmin.java	Fri Aug 01 13:31:03 2014 +0200
@@ -30,6 +30,7 @@
 
 import com.sun.jmx.remote.util.ClassLogger;
 import com.sun.jmx.remote.util.EnvHelp;
+import sun.misc.ManagedLocalsThread;
 
 public abstract class ClientCommunicatorAdmin {
     private static volatile long threadNo = 1;
@@ -40,7 +41,11 @@
         if (period > 0) {
             checker = new Checker();
 
-            Thread t = new Thread(checker, "JMX client heartbeat " + ++threadNo);
+            Thread t = new ManagedLocalsThread(
+                checker,
+                "JMX client heartbeat " +  (++threadNo)
+            );
+
             t.setDaemon(true);
             t.start();
         } else
--- a/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientNotifForwarder.java	Thu Apr 02 11:43:11 2015 +0100
+++ b/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientNotifForwarder.java	Fri Aug 01 13:31:03 2014 +0200
@@ -52,6 +52,7 @@
 import com.sun.jmx.remote.util.ClassLogger;
 import com.sun.jmx.remote.util.EnvHelp;
 import java.rmi.UnmarshalException;
+import sun.misc.ManagedLocalsThread;
 
 
 public abstract class ClientNotifForwarder {
@@ -90,10 +91,8 @@
                 throw new IllegalArgumentException("More than one command");
             this.command = command;
             if (thread == null) {
-                thread = new Thread() {
-
-                    @Override
-                    public void run() {
+                thread = new ManagedLocalsThread(
+                    ()-> {
                         while (true) {
                             Runnable r;
                             synchronized (LinearExecutor.this) {
@@ -107,10 +106,10 @@
                             }
                             r.run();
                         }
-                    }
-                };
+                    },
+                    "ClientNotifForwarder-" + ++threadId
+                );
                 thread.setDaemon(true);
-                thread.setName("ClientNotifForwarder-" + ++threadId);
                 thread.start();
             }
         }
--- a/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ServerCommunicatorAdmin.java	Thu Apr 02 11:43:11 2015 +0100
+++ b/jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ServerCommunicatorAdmin.java	Fri Aug 01 13:31:03 2014 +0200
@@ -25,9 +25,9 @@
 
 package com.sun.jmx.remote.internal;
 
-import java.io.IOException;
 
 import com.sun.jmx.remote.util.ClassLogger;
+import sun.misc.ManagedLocalsThread;
 
 public abstract class ServerCommunicatorAdmin {
     public ServerCommunicatorAdmin(long timeout) {
@@ -42,7 +42,7 @@
         timestamp = 0;
         if (timeout < Long.MAX_VALUE) {
             Runnable timeoutTask = new Timeout();
-            final Thread t = new Thread(timeoutTask);
+            final Thread t = new ManagedLocalsThread(timeoutTask);
             t.setName("JMX server connection timeout " + t.getId());
             // If you change this name you will need to change a unit test
             // (NoServerTimeoutTest)
--- a/jdk/src/java.management/share/classes/javax/management/monitor/Monitor.java	Thu Apr 02 11:43:11 2015 +0100
+++ b/jdk/src/java.management/share/classes/javax/management/monitor/Monitor.java	Fri Aug 01 13:31:03 2014 +0200
@@ -61,6 +61,7 @@
 import javax.management.ObjectName;
 import javax.management.ReflectionException;
 import static javax.management.monitor.MonitorNotification.*;
+import sun.misc.ManagedLocalsThread;
 
 /**
  * Defines the part common to all monitor MBeans.
@@ -1636,12 +1637,12 @@
         }
 
         public Thread newThread(Runnable r) {
-            Thread t = new Thread(group,
-                                  r,
-                                  namePrefix +
-                                  threadNumber.getAndIncrement() +
-                                  nameSuffix,
-                                  0);
+            Thread t = new ManagedLocalsThread(
+                group,
+                r,
+                namePrefix + threadNumber.getAndIncrement() + nameSuffix
+            );
+
             t.setDaemon(true);
             if (t.getPriority() != Thread.NORM_PRIORITY)
                 t.setPriority(Thread.NORM_PRIORITY);
--- a/jdk/src/java.management/share/classes/sun/management/jdp/JdpController.java	Thu Apr 02 11:43:11 2015 +0100
+++ b/jdk/src/java.management/share/classes/sun/management/jdp/JdpController.java	Fri Aug 01 13:31:03 2014 +0200
@@ -34,6 +34,7 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import sun.management.VMManagement;
+import sun.misc.ManagedLocalsThread;
 
 /**
  * JdpController is responsible to create and manage a broadcast loop
@@ -219,7 +220,7 @@
 
         controller = new JDPControllerRunner(bcast, packet, pause);
 
-        Thread t = new Thread(controller, "JDP broadcaster");
+        Thread t = new ManagedLocalsThread(controller, "JDP broadcaster");
         t.setDaemon(true);
         t.start();
     }