Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.rmi/share/classes/sun/rmi/runtime/RuntimeUtil.java
41153 views
1
/*
2
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.rmi.runtime;
27
28
import java.security.AccessController;
29
import java.security.Permission;
30
import java.security.PrivilegedAction;
31
import java.util.concurrent.ScheduledThreadPoolExecutor;
32
import java.util.concurrent.ThreadFactory;
33
import java.util.concurrent.atomic.AtomicInteger;
34
import java.util.logging.Level;
35
36
/**
37
* RMI runtime implementation utilities.
38
*
39
* There is a single instance of this class, which can be obtained
40
* with a GetInstanceAction. Getting the instance requires
41
* RuntimePermission("sun.rmi.runtime.RuntimeUtil.getInstance")
42
* because the public methods of this class expose security-sensitive
43
* capabilities.
44
*
45
* @author Peter Jones
46
**/
47
public final class RuntimeUtil {
48
49
/** runtime package log */
50
private static final Log runtimeLog =
51
Log.getLog("sun.rmi.runtime", null, false);
52
53
/** number of scheduler threads */
54
@SuppressWarnings("removal")
55
private static final int schedulerThreads = // default 1
56
AccessController.doPrivileged((PrivilegedAction<Integer>) () ->
57
Integer.getInteger("sun.rmi.runtime.schedulerThreads", 1));
58
59
/** permission required to get instance */
60
private static final Permission GET_INSTANCE_PERMISSION =
61
new RuntimePermission("sun.rmi.runtime.RuntimeUtil.getInstance");
62
63
/** the singleton instance of this class */
64
private static final RuntimeUtil instance = new RuntimeUtil();
65
66
/** thread pool for scheduling delayed tasks */
67
private final ScheduledThreadPoolExecutor scheduler;
68
69
private RuntimeUtil() {
70
scheduler = new ScheduledThreadPoolExecutor(
71
schedulerThreads,
72
new ThreadFactory() {
73
private final AtomicInteger count = new AtomicInteger();
74
@SuppressWarnings("removal")
75
public Thread newThread(Runnable runnable) {
76
try {
77
return AccessController.doPrivileged(
78
new NewThreadAction(runnable,
79
"Scheduler(" + count.getAndIncrement() + ")",
80
true));
81
} catch (Throwable t) {
82
runtimeLog.log(Level.WARNING,
83
"scheduler thread factory throws", t);
84
return null;
85
}
86
}
87
});
88
/*
89
* We would like to allow the scheduler's threads to terminate
90
* if possible, but a bug in DelayQueue.poll can cause code
91
* like this to result in a busy loop:
92
*/
93
// stpe.setKeepAliveTime(10, TimeUnit.MINUTES);
94
// stpe.allowCoreThreadTimeOut(true);
95
}
96
97
/**
98
* A PrivilegedAction for getting the RuntimeUtil instance.
99
**/
100
public static class GetInstanceAction
101
implements PrivilegedAction<RuntimeUtil>
102
{
103
/**
104
* Creates an action that returns the RuntimeUtil instance.
105
**/
106
public GetInstanceAction() {
107
}
108
109
public RuntimeUtil run() {
110
return getInstance();
111
}
112
}
113
114
private static RuntimeUtil getInstance() {
115
@SuppressWarnings("removal")
116
SecurityManager sm = System.getSecurityManager();
117
if (sm != null) {
118
sm.checkPermission(GET_INSTANCE_PERMISSION);
119
}
120
return instance;
121
}
122
123
/**
124
* Returns the shared thread pool for scheduling delayed tasks.
125
*
126
* Note that the returned pool has limited concurrency, so
127
* submitted tasks should be short-lived and should not block.
128
**/
129
public ScheduledThreadPoolExecutor getScheduler() {
130
return scheduler;
131
}
132
}
133
134