shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdem...@apache.org
Subject shiro git commit: SHIRO-514 ExecutorServiceSessionValidationScheduler creates threads with a configurable name
Date Thu, 07 Jul 2016 17:35:12 GMT
Repository: shiro
Updated Branches:
  refs/heads/1.3.x e3b899939 -> e95e9cf55


SHIRO-514 ExecutorServiceSessionValidationScheduler creates threads with a configurable name


Project: http://git-wip-us.apache.org/repos/asf/shiro/repo
Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/e95e9cf5
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/e95e9cf5
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/e95e9cf5

Branch: refs/heads/1.3.x
Commit: e95e9cf558c663c4be64e20b391de41b8acc8f14
Parents: e3b8999
Author: Brian Demers <bdemers@apache.org>
Authored: Thu Jul 7 12:59:47 2016 -0400
Committer: Brian Demers <bdemers@apache.org>
Committed: Thu Jul 7 13:00:10 2016 -0400

----------------------------------------------------------------------
 ...ecutorServiceSessionValidationScheduler.java | 23 +++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/shiro/blob/e95e9cf5/core/src/main/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationScheduler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationScheduler.java
b/core/src/main/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationScheduler.java
index 3b4cf70..38f5109 100644
--- a/core/src/main/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationScheduler.java
+++ b/core/src/main/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationScheduler.java
@@ -22,6 +22,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -45,6 +46,7 @@ public class ExecutorServiceSessionValidationScheduler implements SessionValidat
     private ScheduledExecutorService service;
     private long interval = DefaultSessionManager.DEFAULT_SESSION_VALIDATION_INTERVAL;
     private boolean enabled = false;
+    private String threadNamePrefix = "SessionValidationThread-";
 
     public ExecutorServiceSessionValidationScheduler() {
         super();
@@ -74,6 +76,14 @@ public class ExecutorServiceSessionValidationScheduler implements SessionValidat
         return this.enabled;
     }
 
+    public void setThreadNamePrefix(String threadNamePrefix) {
+        this.threadNamePrefix = threadNamePrefix;
+    }
+
+    public String getThreadNamePrefix() {
+        return this.threadNamePrefix;
+    }
+
     /**
      * Creates a single thread {@link ScheduledExecutorService} to validate sessions at fixed
intervals 
      * and enables this scheduler. The executor is created as a daemon thread to allow JVM
to shut down
@@ -83,11 +93,14 @@ public class ExecutorServiceSessionValidationScheduler implements SessionValidat
     public void enableSessionValidation() {
         if (this.interval > 0l) {
             this.service = Executors.newSingleThreadScheduledExecutor(new ThreadFactory()
{  
-	        public Thread newThread(Runnable r) {  
-	            Thread thread = new Thread(r);  
-	            thread.setDaemon(true);  
-	            return thread;  
-                }  
+	            private final AtomicInteger count = new AtomicInteger(1);
+
+	            public Thread newThread(Runnable r) {  
+	                Thread thread = new Thread(r);  
+	                thread.setDaemon(true);  
+	                thread.setName(threadNamePrefix + count.getAndIncrement());
+	                return thread;  
+	            }  
             });                  
             this.service.scheduleAtFixedRate(this, interval, interval, TimeUnit.MILLISECONDS);
         }


Mime
View raw message