[ISSUE#3275]Fix the problem that 1.3.1-BETA SDK LifeCycle can't be shutdown for some thread executors. (#3280)

* [#3275]resolve the issue that lifecycle can't be shutdown for some thread executors.

* [ISSUE#3275]do close for upsocket in shutdown method.

* [ISSUE#3249]fix typo.
This commit is contained in:
Hu Zongtang 2020-07-08 16:54:40 +08:00 committed by GitHub
parent 9e9b95b9a0
commit 2342952b63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -54,6 +54,8 @@ public class EventDispatcher implements Closeable {
private final ConcurrentMap<String, List<EventListener>> observerMap = new ConcurrentHashMap<String, List<EventListener>>();
private volatile boolean closed = false;
public EventDispatcher() {
this.executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
@ -146,6 +148,7 @@ public class EventDispatcher implements Closeable {
String className = this.getClass().getName();
NAMING_LOGGER.info("{} do shutdown begin", className);
ThreadUtils.shutdownThreadPool(executor, NAMING_LOGGER);
closed = true;
NAMING_LOGGER.info("{} do shutdown stop", className);
}
@ -153,7 +156,8 @@ public class EventDispatcher implements Closeable {
@Override
public void run() {
while (true) {
while (!closed) {
ServiceInfo serviceInfo = null;
try {
serviceInfo = changedServices.poll(5, TimeUnit.MINUTES);

View File

@ -362,6 +362,8 @@ public class HostReactor implements Closeable {
String className = this.getClass().getName();
NAMING_LOGGER.info("{} do shutdown begin", className);
ThreadUtils.shutdownThreadPool(executor, NAMING_LOGGER);
pushReceiver.shutdown();
failoverReactor.shutdown();
NAMING_LOGGER.info("{} do shutdown stop", className);
}

View File

@ -47,11 +47,12 @@ public class PushReceiver implements Runnable, Closeable {
private HostReactor hostReactor;
private volatile boolean closed = false;
public PushReceiver(HostReactor hostReactor) {
try {
this.hostReactor = hostReactor;
this.udpSocket = new DatagramSocket();
this.executorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
@ -70,8 +71,9 @@ public class PushReceiver implements Runnable, Closeable {
@Override
public void run() {
while (true) {
while (!closed) {
try {
// byte[] is initialized with 0 full filled by default
byte[] buffer = new byte[UDP_MSS];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
@ -113,6 +115,8 @@ public class PushReceiver implements Runnable, Closeable {
String className = this.getClass().getName();
NAMING_LOGGER.info("{} do shutdown begin", className);
ThreadUtils.shutdownThreadPool(executorService, NAMING_LOGGER);
closed = true;
udpSocket.close();
NAMING_LOGGER.info("{} do shutdown stop", className);
}