You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bd...@apache.org on 2016/07/07 17:35:06 UTC
shiro git commit: SHIRO-514 ExecutorServiceSessionValidationScheduler
creates threads with a configurable name
Repository: shiro
Updated Branches:
refs/heads/master 48980e1e2 -> 00beeef0f
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/00beeef0
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/00beeef0
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/00beeef0
Branch: refs/heads/master
Commit: 00beeef0fa928403c6ad2f3b57f0eb1322827829
Parents: 48980e1
Author: Brian Demers <bd...@apache.org>
Authored: Thu Jul 7 12:59:47 2016 -0400
Committer: Brian Demers <bd...@apache.org>
Committed: Thu Jul 7 12:59:47 2016 -0400
----------------------------------------------------------------------
...ecutorServiceSessionValidationScheduler.java | 23 +++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/shiro/blob/00beeef0/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);
}