Sitelet https://github.com/keep-trying-00/java/commit/eea8d429406fc902d73682d90afc644a470c4799
Skip to content

Commit eea8d42

Browse files
author
Devendra
committed
fix for race condition where new worker is getting created after shutdown
1 parent b06d815 commit eea8d42

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎java/srcPubnubApi/srcCore/com/pubnub/api/RequestManager.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ abstract class RequestManager {
137137
protected Hashtable headers;
138138
private static int count = 0;
139139
private boolean daemonThreads = false;
140+
protected volatile boolean stop = false;
140141

141142
protected static Logger log = new Logger(RequestManager.class);
142143

@@ -154,6 +155,8 @@ private void initManager(int maxCalls, String name) {
154155
this.headers = new Hashtable();
155156
_workers = new Worker[maxCalls];
156157

158+
if (stop) return;
159+
157160
synchronized (_workers) {
158161
for (int i = 0; i < maxCalls; ++i) {
159162
Worker w = getWorker();
@@ -207,6 +210,9 @@ public void resetWorkers() {
207210
resetter.start();
208211

209212
_workers[i].interruptWorker();
213+
214+
if (stop) return;
215+
210216
Worker w = getWorker();
211217

212218
PnThread thread = new PnThread(w, name + "-" + ++count);
@@ -249,10 +255,14 @@ public static void setWorkerCount(int count) {
249255
}
250256

251257
public void stop() {
258+
stop = true;
252259
synchronized (_workers) {
253260
for (int i = 0; i < _maxWorkers; ++i) {
254261
Worker w = _workers[i];
255262
w.die();
263+
PnThread resetter = new PnThread(new ConnectionResetter(w));
264+
resetter.setPnDaemon(daemonThreads);
265+
resetter.start();
256266
}
257267
}
258268
synchronized (_waiting) {

0 commit comments

Comments
 (0)