@@ -57,6 +57,9 @@ private SchedulerPoolFactory() {
57
57
* Starts the purge thread if not already started.
58
58
*/
59
59
public static void start () {
60
+ if (!PURGE_ENABLED ) {
61
+ return ;
62
+ }
60
63
for (;;) {
61
64
ScheduledExecutorService curr = PURGE_THREAD .get ();
62
65
if (curr != null && !curr .isShutdown ()) {
@@ -78,7 +81,10 @@ public static void start() {
78
81
* Stops the purge thread.
79
82
*/
80
83
public static void shutdown () {
81
- PURGE_THREAD .get ().shutdownNow ();
84
+ ScheduledExecutorService exec = PURGE_THREAD .get ();
85
+ if (exec != null ) {
86
+ exec .shutdownNow ();
87
+ }
82
88
POOLS .clear ();
83
89
}
84
90
@@ -90,10 +96,10 @@ public static void shutdown() {
90
96
91
97
if (properties .containsKey (PURGE_ENABLED_KEY )) {
92
98
purgeEnable = Boolean .getBoolean (PURGE_ENABLED_KEY );
99
+ }
93
100
94
- if (purgeEnable && properties .containsKey (PURGE_PERIOD_SECONDS_KEY )) {
95
- purgePeriod = Integer .getInteger (PURGE_PERIOD_SECONDS_KEY , purgePeriod );
96
- }
101
+ if (purgeEnable && properties .containsKey (PURGE_PERIOD_SECONDS_KEY )) {
102
+ purgePeriod = Integer .getInteger (PURGE_PERIOD_SECONDS_KEY , purgePeriod );
97
103
}
98
104
99
105
PURGE_ENABLED = purgeEnable ;
@@ -109,7 +115,7 @@ public static void shutdown() {
109
115
*/
110
116
public static ScheduledExecutorService create (ThreadFactory factory ) {
111
117
final ScheduledExecutorService exec = Executors .newScheduledThreadPool (1 , factory );
112
- if (exec instanceof ScheduledThreadPoolExecutor ) {
118
+ if (PURGE_ENABLED && exec instanceof ScheduledThreadPoolExecutor ) {
113
119
ScheduledThreadPoolExecutor e = (ScheduledThreadPoolExecutor ) exec ;
114
120
POOLS .put (e , exec );
115
121
}
0 commit comments