< prev index next >

src/java.base/share/classes/java/lang/ProcessHandleImpl.java

Print this page

 72             completions = new ConcurrentHashMap<>();
 73 
 74     static {
 75         initNative();
 76         long pid = getCurrentPid0();
 77         current = new ProcessHandleImpl(pid, isAlive0(pid));
 78     }
 79 
 80     private static native void initNative();
 81 
 82     /**
 83      * The thread pool of "process reaper" daemon threads.
 84      */
 85     @SuppressWarnings("removal")
 86     private static final Executor processReaperExecutor =
 87             AccessController.doPrivileged((PrivilegedAction<Executor>) () -> {
 88                 // Initialize ThreadLocalRandom now to avoid using the smaller stack
 89                 // of the processReaper threads.
 90                 ThreadLocalRandom.current();
 91 

 92                 ThreadGroup tg = Thread.currentThread().getThreadGroup();
 93                 while (tg.getParent() != null) tg = tg.getParent();
 94                 ThreadGroup systemThreadGroup = tg;
 95 
 96                 // For a debug build, the stack shadow zone is larger;
 97                 // Increase the total stack size to avoid potential stack overflow.
 98                 int debugDelta = "release".equals(System.getProperty("jdk.debug")) ? 0 : (4*4096);
 99                 final long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize")
100                         ? 0 : REAPER_DEFAULT_STACKSIZE + debugDelta;
101 
102                 ThreadFactory threadFactory = grimReaper -> {
103                     Thread t = new Thread(systemThreadGroup, grimReaper,
104                             "process reaper", stackSize, false);
105                     t.setDaemon(true);
106                     // A small attempt (probably futile) to avoid priority inversion
107                     t.setPriority(Thread.MAX_PRIORITY);
108                     return t;
109                 };
110 
111                 return Executors.newCachedThreadPool(threadFactory);

 72             completions = new ConcurrentHashMap<>();
 73 
 74     static {
 75         initNative();
 76         long pid = getCurrentPid0();
 77         current = new ProcessHandleImpl(pid, isAlive0(pid));
 78     }
 79 
 80     private static native void initNative();
 81 
 82     /**
 83      * The thread pool of "process reaper" daemon threads.
 84      */
 85     @SuppressWarnings("removal")
 86     private static final Executor processReaperExecutor =
 87             AccessController.doPrivileged((PrivilegedAction<Executor>) () -> {
 88                 // Initialize ThreadLocalRandom now to avoid using the smaller stack
 89                 // of the processReaper threads.
 90                 ThreadLocalRandom.current();
 91 
 92                 @SuppressWarnings("deprecation")
 93                 ThreadGroup tg = Thread.currentThread().getThreadGroup();
 94                 while (tg.getParent() != null) tg = tg.getParent();
 95                 ThreadGroup systemThreadGroup = tg;
 96 
 97                 // For a debug build, the stack shadow zone is larger;
 98                 // Increase the total stack size to avoid potential stack overflow.
 99                 int debugDelta = "release".equals(System.getProperty("jdk.debug")) ? 0 : (4*4096);
100                 final long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize")
101                         ? 0 : REAPER_DEFAULT_STACKSIZE + debugDelta;
102 
103                 ThreadFactory threadFactory = grimReaper -> {
104                     Thread t = new Thread(systemThreadGroup, grimReaper,
105                             "process reaper", stackSize, false);
106                     t.setDaemon(true);
107                     // A small attempt (probably futile) to avoid priority inversion
108                     t.setPriority(Thread.MAX_PRIORITY);
109                     return t;
110                 };
111 
112                 return Executors.newCachedThreadPool(threadFactory);
< prev index next >