You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:26:37 UTC
[sling-org-apache-sling-commons-threads] 06/09: SLING-5343 -
Meaningful thread names
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.commons.threads-3.2.4
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-threads.git
commit 6935268684b0586bbfd55c1568492c1482cf994a
Author: Julian Sedding <js...@apache.org>
AuthorDate: Mon Dec 7 09:53:29 2015 +0000
SLING-5343 - Meaningful thread names
- change thread name format due to mailing list discussions
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/threads@1718272 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/commons/threads/impl/ExtendedThreadFactory.java | 10 ++++++++--
.../sling/commons/threads/impl/ExtendedThreadFactoryTest.java | 8 ++++----
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactory.java b/src/main/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactory.java
index c587d20..15dfedd 100644
--- a/src/main/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactory.java
+++ b/src/main/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactory.java
@@ -16,6 +16,7 @@
*/
package org.apache.sling.commons.threads.impl;
+import java.util.Locale;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
@@ -30,7 +31,7 @@ import org.apache.sling.commons.threads.ThreadPoolConfig;
public final class ExtendedThreadFactory implements ThreadFactory {
/** Template for thread names, for use with String#format() */
- private static final String THREAD_NAME_TEMPLATE = "Sling - %s #%d";
+ private static final String THREAD_NAME_TEMPLATE = "sling-%s-%d";
/** The real factory. */
private final ThreadFactory factory;
@@ -59,12 +60,17 @@ public final class ExtendedThreadFactory implements ThreadFactory {
final ThreadPoolConfig.ThreadPriority priority,
final boolean isDaemon) {
this.factory = factory;
- this.name = stripPrefixes(name, "Apache Sling ", "Sling ");
+ this.name = normalizeName(name);
this.priority = convertPriority(priority);
this.isDaemon = isDaemon;
this.threadCounter = new AtomicInteger(1);
}
+ private String normalizeName(final String name) {
+ final String n = name.toLowerCase(Locale.ENGLISH).replaceAll("\\s+", "-");
+ return stripPrefixes(n, "apache-sling-", "sling-");
+ }
+
private int convertPriority(final ThreadPoolConfig.ThreadPriority priority) {
if (priority == null) {
throw new IllegalStateException("Prioriy must not be null.");
diff --git a/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java b/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
index 7ebd5f0..4c80d93 100644
--- a/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
+++ b/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
@@ -33,20 +33,20 @@ public class ExtendedThreadFactoryTest {
@Test
public void informativeThreadNames() {
final ExtendedThreadFactory tf = factory("Test Pool");
- assertEquals("Thread name", "Sling - Test Pool #1", tf.newThread(null).getName());
- assertEquals("Thread name", "Sling - Test Pool #2", tf.newThread(null).getName());
+ assertEquals("Thread name", "sling-test-pool-1", tf.newThread(null).getName());
+ assertEquals("Thread name", "sling-test-pool-2", tf.newThread(null).getName());
}
@Test
public void shouldStripSlingPrefixFromThreadNames() {
final Thread thread = thread("Sling Test Pool");
- assertEquals("Thread name", "Sling - Test Pool #1", thread.getName());
+ assertEquals("Thread name", "sling-test-pool-1", thread.getName());
}
@Test
public void shouldStripApacheSlingPrefixFromThreadNames() {
final Thread thread = thread("Apache Sling Test Pool");
- assertEquals("Thread name", "Sling - Test Pool #1", thread.getName());
+ assertEquals("Thread name", "sling-test-pool-1", thread.getName());
}
@Test
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.