You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2012/08/17 22:26:07 UTC

svn commit: r1374422 - /sling/trunk/bundles/commons/threads/src/main/java/org/apache/sling/commons/threads/impl/DefaultThreadPoolManager.java

Author: justin
Date: Fri Aug 17 20:26:07 2012
New Revision: 1374422

URL: http://svn.apache.org/viewvc?rev=1374422&view=rev
Log:
SLING-2563 - auto generate label based on a stack trace

Modified:
    sling/trunk/bundles/commons/threads/src/main/java/org/apache/sling/commons/threads/impl/DefaultThreadPoolManager.java

Modified: sling/trunk/bundles/commons/threads/src/main/java/org/apache/sling/commons/threads/impl/DefaultThreadPoolManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/threads/src/main/java/org/apache/sling/commons/threads/impl/DefaultThreadPoolManager.java?rev=1374422&r1=1374421&r2=1374422&view=diff
==============================================================================
--- sling/trunk/bundles/commons/threads/src/main/java/org/apache/sling/commons/threads/impl/DefaultThreadPoolManager.java (original)
+++ sling/trunk/bundles/commons/threads/src/main/java/org/apache/sling/commons/threads/impl/DefaultThreadPoolManager.java Fri Aug 17 20:26:07 2012
@@ -161,6 +161,19 @@ public class DefaultThreadPoolManager
         if ( config == null ) {
             throw new IllegalArgumentException("Config must not be null.");
         }
+
+        if ( label == null ) {
+            // generate the label by taking the first external frame off the stack trace
+            final StackTraceElement[] stackTrace = new Exception().getStackTrace();
+            if ( stackTrace != null && stackTrace.length > 1 ) {
+                if ( stackTrace[1].getClassName().equals( this.getClass().getName() ) ) {
+                    label = stackTrace[2].getClassName();
+                } else {
+                    label = stackTrace[1].getClassName();
+                }
+            }
+        }
+
         final String name = "ThreadPool-" + UUID.randomUUID().toString() +
              (label == null ? "" : " (" + label + ")");
         final Entry entry = new Entry(null, config, name);