Permalink
Browse files

Changed back from singleton, clarified method naming and added a stat…

…ic factory method.
  • Loading branch information...
1 parent ca20d46 commit 2f4a54dad550225923e8519d428ab920f5704018 @gorzell committed Apr 4, 2012
Showing with 8 additions and 9 deletions.
  1. +8 −9 metrics-core/src/main/java/com/yammer/metrics/core/ThreadPools.java
@@ -39,16 +39,10 @@ public Thread newThread(Runnable r) {
}
}
- private final ConcurrentMap<String, ScheduledExecutorService> threadPools =
- new ConcurrentHashMap<String, ScheduledExecutorService>(100);
+ private final ConcurrentMap<String, ScheduledExecutorService> threadPools = new ConcurrentHashMap<String, ScheduledExecutorService>(100);
- private static ThreadPools ourInstance = new ThreadPools();
- public static ThreadPools getInstance() {
- return ourInstance;
- }
-
- private ThreadPools(){}
+ ThreadPools(){}
/**
* Creates a new scheduled thread pool of a given size with the given name, or returns an
* existing thread pool if one was already created with the same name.
@@ -57,7 +51,7 @@ private ThreadPools(){}
* @param name the name of the pool
* @return a new {@link ScheduledExecutorService}
*/
- public ScheduledExecutorService newScheduledThreadPool(int poolSize, String name) {
+ public ScheduledExecutorService exisitingOrNewScheduledThreadPool(int poolSize, String name) {
final ScheduledExecutorService existing = threadPools.get(name);
if (isValidExecutor(existing)) {
return existing;
@@ -80,6 +74,11 @@ public ScheduledExecutorService newScheduledThreadPool(int poolSize, String name
}
}
+ public static ScheduledExecutorService newScheduledThreadPool(int poolSize, String name) {
+ return Executors.newScheduledThreadPool(poolSize, new NamedThreadFactory(name));
+ }
+
+
private static boolean isValidExecutor(ExecutorService executor) {
return executor != null && !executor.isShutdown() && !executor.isTerminated();
}

0 comments on commit 2f4a54d

Please sign in to comment.