Skip to content

Commit

Permalink
Cleanup and optimize thread pool shutdown, fix "DISCONNECTED" status
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian S committed Jan 3, 2020
1 parent 380572e commit 26fc50c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
34 changes: 11 additions & 23 deletions src/main/java/de/csdev/ebus/core/EBusControllerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,26 @@ protected void shutdownThreadPool() {
// shutdown threadpool
if (threadPool != null && !threadPool.isShutdown()) {
threadPool.shutdownNow();
}

if (threadPoolWDT != null && !threadPoolWDT.isShutdown()) {
threadPoolWDT.shutdownNow();
}

if (threadPool != null) {
try {
// wait up to 10sec. for the thread pool
threadPool.awaitTermination(10, TimeUnit.SECONDS);
threadPool = null;
} catch (InterruptedException e) {
}
}

if (threadPoolWDT != null && !threadPoolWDT.isShutdown()) {
threadPoolWDT.shutdownNow();
if (threadPoolWDT != null) {
try {
// wait up to 10sec. for the thread pool
threadPoolWDT.awaitTermination(10, TimeUnit.SECONDS);
threadPoolWDT = null;
} catch (InterruptedException e) {
}
}
Expand Down Expand Up @@ -276,23 +284,11 @@ protected void dispose() {
}

protected void resetWatchdogTimer() {

// logger.info("wdt runn ...");

Runnable r = new Runnable() {

@Override
public void run() {
EBusControllerBase.this.fireWatchDogTimer();
// EBusControllerBase.logger.warn("eBUS Watchdog Timer!");
//
// try {
// EBusControllerBase.this.connection.close();
// } catch (IOException e) {
// logger.error("error!", e);
// }
}

};

if (watchdogTimer != null && !watchdogTimer.isCancelled()) {
Expand All @@ -315,15 +311,7 @@ public void setWatchdogTimerTimeout(int seconds) {
watchdogTimerTimeout = seconds;
}

protected void fireWatchDogTimer() {
// EBusControllerBase.logger.warn("eBUS Watchdog Timer!");
//
// try {
// EBusControllerBase.this.connection.close();
// } catch (IOException e) {
// logger.error("error!", e);
// }
}
protected abstract void fireWatchDogTimer();

protected void setConnectionStatus(ConnectionStatus status) {
this.connectionStatus = status;
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/de/csdev/ebus/core/EBusLowLevelController.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ public void run() {
resetWatchdogTimer();

// loop until interrupt or reconnector count is -1 (to many retries)

// while (!Thread.currentThread().isInterrupted() || reConnectCounter != -1) {

while (!(this.isInterrupted() || reConnectCounter == -1)) {
try {

Expand Down Expand Up @@ -419,6 +416,9 @@ protected void dispose() {

logger.info("eBUS connection thread is shuting down ...");

// set connection status to disconnected
setConnectionStatus(ConnectionStatus.DISCONNECTED);

super.dispose();

// *******************************
Expand All @@ -435,8 +435,6 @@ protected void dispose() {
logger.error(e.toString(), e);
}

// set connection status to disconnected
setConnectionStatus(ConnectionStatus.DISCONNECTED);
}

@Override
Expand Down

0 comments on commit 26fc50c

Please sign in to comment.