Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ThreadPool keeping standalone application alive #663

Merged
merged 5 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# CHANGELOG

# Version 2.1.2
- Fix [#662](https://github.com/Microsoft/ApplicationInsights-Java/issues/662). Updated thread pool to properly shutdown all threads.

# Version 2.1.1
- Introducing support for SpringBoot via Application-Insights-SpringBoot-Starter [#646](https://github.com/Microsoft/ApplicationInsights-Java/pull/646). This is currently in beta.
- In order to add support for SpringBoot starter some fields in core SDK are made public.
- Introduced public constructor in `InProcessTelemetryChannel.java` class.
- Introduced a public method `getActiveWithoutInitializingConfig()` in `TelemetryConfiguration.java` class.
- Introduced a public method `getActiveWithoutInitializingConfig()` in `TelemetryConfiguration.java` class.

# Version 2.1.0
- Introduced Heartbeat feature which sends periodic heartbeats with basic information about application and runtime to Application Insights.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import com.microsoft.applicationinsights.internal.logger.InternalLogger;

import com.microsoft.applicationinsights.internal.shutdown.SDKShutdownActivity;
import com.microsoft.applicationinsights.internal.util.ThreadPoolUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
Expand All @@ -46,7 +49,9 @@ final class ApacheSender43 implements ApacheSender {

private final AtomicReference<CloseableHttpClient> httpClientRef = new AtomicReference<>();
private volatile boolean isClientInitialized = false;
private final ExecutorService initializer = Executors.newSingleThreadExecutor();
private final ExecutorService initializer = new ThreadPoolExecutor(0, 1, 2, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>(),
ThreadPoolUtils.createNamedDaemonThreadFactory(ApacheSender43.class.getSimpleName()+"_initializer"));

public ApacheSender43() {
initializer.execute(new Runnable() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ private SDKShutdownAction getShutdownAction() {
if (shutdownAction == null) {
try {
shutdownAction = new SDKShutdownAction();
Runtime.getRuntime().addShutdownHook(new Thread(shutdownAction, SDKShutdownActivity.class.getSimpleName()));
Thread t = new Thread(shutdownAction, SDKShutdownActivity.class.getSimpleName());
t.setDaemon(true);
Runtime.getRuntime().addShutdownHook(t);
} catch (Exception e) {
InternalLogger.INSTANCE.error("Error while adding shutdown hook in getShutDownThread call");
InternalLogger.INSTANCE.trace("Stack trace generated is %s", ExceptionUtils.getStackTrace(e));
Expand Down