You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2018/11/09 13:44:39 UTC
svn commit: r1846245 - in /tomcat/trunk:
java/org/apache/catalina/core/StandardService.java
webapps/docs/config/service.xml
Author: remm
Date: Fri Nov 9 13:44:39 2018
New Revision: 1846245
URL: http://svn.apache.org/viewvc?rev=1846245&view=rev
Log:
Add a daemon flag for the utility threads. Those threads are not bad candidates for non daemon by default, given they are managed by an executor.
Modified:
tomcat/trunk/java/org/apache/catalina/core/StandardService.java
tomcat/trunk/webapps/docs/config/service.xml
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardService.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardService.java?rev=1846245&r1=1846244&r2=1846245&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardService.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardService.java Fri Nov 9 13:44:39 2018
@@ -100,6 +100,11 @@ public class StandardService extends Lif
protected int utilityThreads = 0;
/**
+ * The utility threads daemon flag.
+ */
+ protected boolean utilityThreadsAsDaemon = true;
+
+ /**
* Utility executor with scheduling capabilities.
*/
private ScheduledThreadPoolExecutor utilityExecutor = null;
@@ -267,7 +272,8 @@ public class StandardService extends Lif
utilityExecutor.setMaximumPoolSize(threads);
} else {
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor =
- new ScheduledThreadPoolExecutor(1, new UtilityThreadFactory(getName() + "-utility-"));
+ new ScheduledThreadPoolExecutor(1,
+ new UtilityThreadFactory(getName() + "-utility-", utilityThreadsAsDaemon));
scheduledThreadPoolExecutor.setMaximumPoolSize(threads);
scheduledThreadPoolExecutor.setKeepAliveTime(10, TimeUnit.SECONDS);
scheduledThreadPoolExecutor.setRemoveOnCancelPolicy(true);
@@ -278,6 +284,24 @@ public class StandardService extends Lif
}
+ /**
+ * Get if the utility threads are daemon threads.
+ * @return the threads daemon flag
+ */
+ public boolean getUtilityThreadsAsDaemon() {
+ return utilityThreadsAsDaemon;
+ }
+
+
+ /**
+ * Set the utility threads daemon flag. The default value is true.
+ * @param utilityThreadsAsDaemon the new thread daemon flag
+ */
+ public void setUtilityThreadsAsDaemon(boolean utilityThreadsAsDaemon) {
+ this.utilityThreadsAsDaemon = utilityThreadsAsDaemon;
+ }
+
+
// --------------------------------------------------------- Public Methods
@@ -705,17 +729,19 @@ public class StandardService extends Lif
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;
+ private final boolean daemon;
- public UtilityThreadFactory(String namePrefix) {
+ public UtilityThreadFactory(String namePrefix, boolean daemon) {
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
this.namePrefix = namePrefix;
+ this.daemon = daemon;
}
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(group, r, namePrefix + threadNumber.getAndIncrement());
- thread.setDaemon(true);
+ thread.setDaemon(daemon);
return thread;
}
}
Modified: tomcat/trunk/webapps/docs/config/service.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/service.xml?rev=1846245&r1=1846244&r2=1846245&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/service.xml (original)
+++ tomcat/trunk/webapps/docs/config/service.xml Fri Nov 9 13:44:39 2018
@@ -68,7 +68,7 @@
must be unique.</p>
</attribute>
- <attribute name="startStopThreads" required="false">
+ <attribute name="utilityThreads" required="false">
<p>The number of threads this <strong>Service</strong> will use for
various utility tasks, including recurring ones. The special value
of 0 will result in the value of
@@ -92,6 +92,12 @@
<attributes>
+ <attribute name="utilityThreadsAsDaemon" required="false">
+ <p>Set the daemon flag value for the utility threads. The default value
+ is <code>true</code>.
+ </p>
+ </attribute>
+
</attributes>
</subsection>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org