Skip to content

Commit 634cd9c

Browse files
committed
Using interrupts
1 parent 6c99636 commit 634cd9c

3 files changed

Lines changed: 4 additions & 20 deletions

File tree

‎src/main/java/com/mashape/unirest/http/Unirest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ public static void shutdown() throws IOException {
9696
syncClient.close();
9797

9898
SyncIdleConnectionMonitorThread syncIdleConnectionMonitorThread = (SyncIdleConnectionMonitorThread) Options.getOption(Option.SYNC_MONITOR);
99-
syncIdleConnectionMonitorThread.shutdown();
99+
syncIdleConnectionMonitorThread.interrupt();
100100

101101
// Closing the async client (if running)
102102
CloseableHttpAsyncClient asyncClient = (CloseableHttpAsyncClient) Options.getOption(Option.ASYNCHTTPCLIENT);
103103
if (asyncClient.isRunning()) {
104104
asyncClient.close();
105105
AsyncIdleConnectionMonitorThread asyncIdleConnectionMonitorThread = (AsyncIdleConnectionMonitorThread) Options.getOption(Option.ASYNC_MONITOR);
106-
asyncIdleConnectionMonitorThread.shutdown();
106+
asyncIdleConnectionMonitorThread.interrupt();
107107
}
108108

109109
}

‎src/main/java/com/mashape/unirest/http/async/utils/AsyncIdleConnectionMonitorThread.java‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
public class AsyncIdleConnectionMonitorThread extends Thread {
88

99
private final PoolingNHttpClientConnectionManager connMgr;
10-
private volatile boolean shutdown;
1110

1211
public AsyncIdleConnectionMonitorThread(PoolingNHttpClientConnectionManager connMgr) {
1312
super();
@@ -18,7 +17,7 @@ public AsyncIdleConnectionMonitorThread(PoolingNHttpClientConnectionManager conn
1817
@Override
1918
public void run() {
2019
try {
21-
while (!shutdown) {
20+
while (!Thread.currentThread().isInterrupted()) {
2221
synchronized (this) {
2322
wait(5000);
2423
// Close expired connections
@@ -33,11 +32,4 @@ public void run() {
3332
}
3433
}
3534

36-
public void shutdown() {
37-
shutdown = true;
38-
synchronized (this) {
39-
notifyAll();
40-
}
41-
}
42-
4335
}

‎src/main/java/com/mashape/unirest/http/utils/SyncIdleConnectionMonitorThread.java‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
public class SyncIdleConnectionMonitorThread extends Thread {
88

99
private final HttpClientConnectionManager connMgr;
10-
private volatile boolean shutdown;
1110

1211
public SyncIdleConnectionMonitorThread(HttpClientConnectionManager connMgr) {
1312
super();
@@ -18,7 +17,7 @@ public SyncIdleConnectionMonitorThread(HttpClientConnectionManager connMgr) {
1817
@Override
1918
public void run() {
2019
try {
21-
while (!shutdown) {
20+
while (!Thread.currentThread().isInterrupted()) {
2221
synchronized (this) {
2322
wait(5000);
2423
// Close expired connections
@@ -33,11 +32,4 @@ public void run() {
3332
}
3433
}
3534

36-
public void shutdown() {
37-
shutdown = true;
38-
synchronized (this) {
39-
notifyAll();
40-
}
41-
}
42-
4335
}

0 commit comments

Comments
 (0)