Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not use virtual threads when a SecurityManager is set #821

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions logback-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<packaging>jar</packaging>
<name>Logback Core Module</name>
<description>logback-core module</description>
<version>1.5.11-sm-20241024</version>

<properties>
<module-name>ch.qos.logback.core</module-name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,28 @@
* @author Mikhail Mazursky
*/
public class ExecutorServiceUtil {

private static final boolean NO_SECURITY_MANAGER = System.getSecurityManager() == null;

private static final ThreadFactory THREAD_FACTORY_FOR_SCHEDULED_EXECUTION_SERVICE = new ThreadFactory() {

private final AtomicInteger threadNumber = new AtomicInteger(1);

private final ThreadFactory defaultFactory = makeThreadFactory();

/**
* A thread factory which may be a virtual thread factory the JDK supports it.
* A thread factory which may be a virtual thread factory if the JDK supports it
* and there is no security manager.
*
* @return
*/
private ThreadFactory makeThreadFactory() {
ThreadFactory tf = Thread.ofVirtual().factory();
return tf;
if (NO_SECURITY_MANAGER) {
ThreadFactory tf = Thread.ofVirtual().factory();
return tf;
}

return Executors.defaultThreadFactory();
}

@Override
Expand Down Expand Up @@ -99,11 +107,15 @@ static public void shutdown(ExecutorService executorService) {

/**
* An alternate implementation of {@linl #newThreadPoolExecutor} which returns a virtual thread per task executor
* when available.
* if the JDK supports it and there is no security manager.
*
* @since 1.3.12/1.4.12
*/
static public ExecutorService newAlternateThreadPoolExecutor() {
return Executors.newVirtualThreadPerTaskExecutor();
if (NO_SECURITY_MANAGER) {
return Executors.newVirtualThreadPerTaskExecutor();
}

return newThreadPoolExecutor();
}
}