diff --git a/logback-core/pom.xml b/logback-core/pom.xml
index 2e9d67f1be..31cacd3ef4 100755
--- a/logback-core/pom.xml
+++ b/logback-core/pom.xml
@@ -15,6 +15,7 @@
jar
Logback Core Module
logback-core module
+ 1.5.12-sm
ch.qos.logback.core
diff --git a/logback-core/src/main/java21/ch/qos/logback/core/util/ExecutorServiceUtil.java b/logback-core/src/main/java21/ch/qos/logback/core/util/ExecutorServiceUtil.java
index 221f23447d..e78ce72b7e 100644
--- a/logback-core/src/main/java21/ch/qos/logback/core/util/ExecutorServiceUtil.java
+++ b/logback-core/src/main/java21/ch/qos/logback/core/util/ExecutorServiceUtil.java
@@ -34,6 +34,9 @@
* @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);
@@ -41,13 +44,18 @@ public class ExecutorServiceUtil {
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
@@ -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();
}
}