< prev index next >

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

Print this page

 76     static {
 77         initNative();
 78         long pid = getCurrentPid0();
 79         current = new ProcessHandleImpl(pid, isAlive0(pid));
 80     }
 81 
 82     private static native void initNative();
 83 
 84     /**
 85      * The thread pool of "process reaper" daemon threads.
 86      */
 87     private static final Executor processReaperExecutor = initReaper();
 88 
 89     private static Executor initReaper() {
 90         // Initialize ThreadLocalRandom now to avoid using the smaller stack
 91         // of the processReaper threads.
 92         ThreadLocalRandom.current();
 93 
 94         // For a debug build, the stack shadow zone is larger;
 95         // Increase the total stack size to avoid potential stack overflow.
 96         int debugDelta = "release".equals(System.getProperty("jdk.debug")) ? 0 : (4 * 4096);
 97         final long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize")
 98                 ? 0 : REAPER_DEFAULT_STACKSIZE + debugDelta;
 99 
100         ThreadFactory threadFactory = grimReaper -> {
101             Thread t = InnocuousThread.newSystemThread("process reaper", grimReaper,
102                     stackSize, Thread.MAX_PRIORITY);
103             t.setDaemon(true);
104             return t;
105         };
106 
107         return Executors.newCachedThreadPool(threadFactory);
108     }
109 
110     private static class ExitCompletion extends CompletableFuture<Integer> {
111         final boolean isReaping;
112 
113         ExitCompletion(boolean isReaping) {
114             this.isReaping = isReaping;
115         }
116     }

 76     static {
 77         initNative();
 78         long pid = getCurrentPid0();
 79         current = new ProcessHandleImpl(pid, isAlive0(pid));
 80     }
 81 
 82     private static native void initNative();
 83 
 84     /**
 85      * The thread pool of "process reaper" daemon threads.
 86      */
 87     private static final Executor processReaperExecutor = initReaper();
 88 
 89     private static Executor initReaper() {
 90         // Initialize ThreadLocalRandom now to avoid using the smaller stack
 91         // of the processReaper threads.
 92         ThreadLocalRandom.current();
 93 
 94         // For a debug build, the stack shadow zone is larger;
 95         // Increase the total stack size to avoid potential stack overflow.
 96         int debugDelta = "release".equals(System.getProperty("jdk.debug")) ? 0 : (16 * 4096);
 97         final long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize")
 98                 ? 0 : REAPER_DEFAULT_STACKSIZE + debugDelta;
 99 
100         ThreadFactory threadFactory = grimReaper -> {
101             Thread t = InnocuousThread.newSystemThread("process reaper", grimReaper,
102                     stackSize, Thread.MAX_PRIORITY);
103             t.setDaemon(true);
104             return t;
105         };
106 
107         return Executors.newCachedThreadPool(threadFactory);
108     }
109 
110     private static class ExitCompletion extends CompletableFuture<Integer> {
111         final boolean isReaping;
112 
113         ExitCompletion(boolean isReaping) {
114             this.isReaping = isReaping;
115         }
116     }
< prev index next >