Skip to content

Commit 92e0ce7

Browse files
committed
Stop AsyncHttpDelivery from indefinitely blocking exit
The executor used by AsyncHttpDelivery indefinitely blocks application exit unless a shutdown is manually triggered. This replaces the executor with one which times out when idle and so doesn't block an exit.
1 parent 272cf8b commit 92e0ce7

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/main/java/com/bugsnag/delivery/AsyncHttpDelivery.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@
77

88
import java.net.Proxy;
99
import java.util.concurrent.ExecutorService;
10-
import java.util.concurrent.Executors;
10+
import java.util.concurrent.LinkedBlockingQueue;
11+
import java.util.concurrent.ThreadPoolExecutor;
1112
import java.util.concurrent.TimeUnit;
1213

1314
public class AsyncHttpDelivery implements HttpDelivery {
1415
private static final Logger logger = LoggerFactory.getLogger(AsyncHttpDelivery.class);
1516
private static final int SHUTDOWN_TIMEOUT = 5000;
1617

17-
protected HttpDelivery baseDelivery = new SyncHttpDelivery();
18-
protected ExecutorService executorService = Executors.newSingleThreadExecutor();
18+
private HttpDelivery baseDelivery = new SyncHttpDelivery();
19+
20+
// Create an exector service which keeps idle threads alive for a maximum of SHUTDOWN_TIMEOUT.
21+
// This should avoid blocking an application that doesn't call shutdown from exiting.
22+
private ExecutorService executorService =
23+
new ThreadPoolExecutor(0, 1,
24+
SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS,
25+
new LinkedBlockingQueue<Runnable>());
26+
1927
private boolean shuttingDown = false;
2028

2129
/**

0 commit comments

Comments
 (0)