1
1
/*
2
- * Copyright (c) 2013, 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2013, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -72,13 +72,15 @@ public static Thread newThread(String name, Runnable target) {
72
72
*/
73
73
public static Thread newThread (String name , Runnable target , int priority ) {
74
74
if (System .getSecurityManager () == null ) {
75
- return createThread (name , target , ClassLoader .getSystemClassLoader (), priority );
75
+ return createThread (name , target , 0L ,
76
+ ClassLoader .getSystemClassLoader (), priority );
76
77
}
77
78
return AccessController .doPrivileged (
78
79
new PrivilegedAction <Thread >() {
79
80
@ Override
80
81
public Thread run () {
81
- return createThread (name , target , ClassLoader .getSystemClassLoader (), priority );
82
+ return createThread (name , target , 0L ,
83
+ ClassLoader .getSystemClassLoader (), priority );
82
84
}
83
85
});
84
86
}
@@ -104,28 +106,50 @@ public static Thread newSystemThread(String name, Runnable target) {
104
106
*/
105
107
public static Thread newSystemThread (String name , Runnable target , int priority ) {
106
108
if (System .getSecurityManager () == null ) {
107
- return createThread (name , target , null , priority );
109
+ return createThread (name , target , 0L , null , priority );
108
110
}
109
111
return AccessController .doPrivileged (
110
112
new PrivilegedAction <Thread >() {
111
113
@ Override
112
114
public Thread run () {
113
- return createThread (name , target , null , priority );
115
+ return createThread (name , target , 0L ,
116
+ null , priority );
114
117
}
115
118
});
116
119
}
117
120
118
- private static Thread createThread (String name , Runnable target , ClassLoader loader , int priority ) {
121
+ /**
122
+ * Returns a new InnocuousThread with null context class loader.
123
+ * Thread priority is set to the given priority.
124
+ */
125
+ public static Thread newSystemThread (String name , Runnable target ,
126
+ long stackSize , int priority ) {
127
+ if (System .getSecurityManager () == null ) {
128
+ return createThread (name , target , stackSize , null , priority );
129
+ }
130
+ return AccessController .doPrivileged (
131
+ new PrivilegedAction <Thread >() {
132
+ @ Override
133
+ public Thread run () {
134
+ return createThread (name , target , 0L ,
135
+ null , priority );
136
+ }
137
+ });
138
+ }
139
+
140
+ private static Thread createThread (String name , Runnable target , long stackSize ,
141
+ ClassLoader loader , int priority ) {
119
142
Thread t = new InnocuousThread (INNOCUOUSTHREADGROUP ,
120
- target , name , loader );
143
+ target , name , stackSize , loader );
121
144
if (priority >= 0 ) {
122
145
t .setPriority (priority );
123
146
}
124
147
return t ;
125
148
}
126
149
127
- private InnocuousThread (ThreadGroup group , Runnable target , String name , ClassLoader tccl ) {
128
- super (group , target , name , 0L , false );
150
+ private InnocuousThread (ThreadGroup group , Runnable target , String name ,
151
+ long stackSize , ClassLoader tccl ) {
152
+ super (group , target , name , stackSize , false );
129
153
UNSAFE .putReferenceRelease (this , INHERITEDACCESSCONTROLCONTEXT , ACC );
130
154
UNSAFE .putReferenceRelease (this , CONTEXTCLASSLOADER , tccl );
131
155
}
0 commit comments