提交 cba4dc28 编写于 作者: wu-sheng's avatar wu-sheng

Make sure the JVM stop hook works #295

上级 75ada9fe
......@@ -20,6 +20,7 @@ public class ConsumerPool<T> {
this(channels, num);
for (int i = 0; i < num; i++) {
consumerThreads[i] = new ConsumerThread("DataCarrier.Consumser." + i + ".Thread", getNewConsumerInstance(consumerClass));
consumerThreads[i].setDaemon(true);
}
}
......
package org.skywalking.apm.agent.core.jvm;
import io.grpc.ManagedChannel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import org.skywalking.apm.agent.core.boot.BootService;
import org.skywalking.apm.agent.core.boot.ServiceManager;
import org.skywalking.apm.agent.core.conf.Config;
......@@ -65,6 +62,12 @@ public class JVMService implements BootService, Runnable {
}
@Override
public void shutdown() throws Throwable {
collectMetricFuture.cancel(true);
sendMetricFuture.cancel(true);
}
@Override
public void run() {
if (RemoteDownstreamConfig.Agent.APPLICATION_ID != DictionaryUtil.nullValue()
......
......@@ -77,6 +77,11 @@ public class AppAndServiceRegisterClient implements BootService, GRPCChannelList
TracingContext.ListenerManager.add(this);
}
@Override
public void shutdown() throws Throwable {
applicationRegisterFuture.cancel(true);
}
@Override
public void run() {
if (CONNECTED.equals(status)) {
......
package org.skywalking.apm.agent.core.remote;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.skywalking.apm.agent.core.boot.BootService;
import org.skywalking.apm.agent.core.conf.Config;
......@@ -11,6 +12,8 @@ import org.skywalking.apm.agent.core.conf.Config;
* @author wusheng
*/
public class CollectorDiscoveryService implements BootService {
private ScheduledFuture<?> future;
@Override
public void beforeBoot() throws Throwable {
......@@ -18,7 +21,7 @@ public class CollectorDiscoveryService implements BootService {
@Override
public void boot() throws Throwable {
Executors.newSingleThreadScheduledExecutor()
future = Executors.newSingleThreadScheduledExecutor()
.scheduleAtFixedRate(new DiscoveryRestServiceClient(), 0,
Config.Collector.DISCOVERY_CHECK_INTERVAL, TimeUnit.SECONDS);
}
......@@ -27,4 +30,9 @@ public class CollectorDiscoveryService implements BootService {
public void afterBoot() throws Throwable {
}
@Override
public void shutdown() throws Throwable {
future.cancel(true);
}
}
......@@ -49,6 +49,12 @@ public class GRPCChannelManager implements BootService, Runnable {
}
@Override
public void shutdown() throws Throwable {
connectCheckFuture.cancel(true);
managedChannel.shutdownNow();
}
@Override
public void run() {
if (reconnect) {
......
......@@ -49,6 +49,11 @@ public class TraceSegmentServiceClient implements BootService, IConsumer<TraceSe
TracingContext.ListenerManager.add(this);
}
@Override
public void shutdown() throws Throwable {
carrier.shutdownConsumers();
}
@Override
public void init() {
......
......@@ -61,6 +61,11 @@ public class SamplingService implements BootService {
}
@Override
public void shutdown() throws Throwable {
scheduledFuture.cancel(true);
}
/**
* @return true, if sampling mechanism is on, and get the sampling factor successfully.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册