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

[miio] Avoid shutting down shared executor service #11166

Merged
merged 2 commits into from
Sep 8, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public abstract class MiIoAbstractHandler extends BaseThingHandler implements Mi
protected static final Gson GSON = new GsonBuilder().create();
protected static final String TIMESTAMP = "timestamp";

protected ScheduledExecutorService miIoScheduler = scheduler;
protected ScheduledExecutorService miIoScheduler = new ScheduledThreadPoolExecutor(3,
new NamedThreadFactory("binding-" + getThing().getUID().getAsString(), true));

protected @Nullable ScheduledFuture<?> pollingJob;
protected MiIoDevices miDevice = MiIoDevices.UNKNOWN;
protected boolean isIdentified;
Expand Down Expand Up @@ -134,7 +136,7 @@ public void initialize() {
getThing().getThingTypeUID());

ScheduledThreadPoolExecutor miIoScheduler = new ScheduledThreadPoolExecutor(3,
new NamedThreadFactory(getThing().getUID().getAsString(), true));
new NamedThreadFactory("binding-" + getThing().getUID().getAsString(), true));
miIoScheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
miIoScheduler.setRemoveOnCancelPolicy(true);
this.miIoScheduler = miIoScheduler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ MiIoSendCommand sendMiIoSendCommand(MiIoSendCommand miIoSendCommand) {
public synchronized void startReceiver() {
MessageSenderThread senderThread = this.senderThread;
if (senderThread == null || !senderThread.isAlive()) {
senderThread = new MessageSenderThread();
senderThread = new MessageSenderThread(deviceId);
senderThread.start();
this.senderThread = senderThread;
}
Expand All @@ -261,14 +261,17 @@ public synchronized void startReceiver() {
*
*/
private class MessageSenderThread extends Thread {
public MessageSenderThread() {
super("Mi IO MessageSenderThread");
private final String deviceId;

public MessageSenderThread(String deviceId) {
super("OH-binding-miio-MessageSenderThread-" + deviceId);
setDaemon(true);
this.deviceId = deviceId;
}

@Override
public void run() {
logger.debug("Starting Mi IO MessageSenderThread");
logger.debug("Starting Mi IO MessageSenderThread {}", deviceId);
while (!interrupted()) {
try {
if (concurrentLinkedQueue.isEmpty()) {
Expand All @@ -291,11 +294,11 @@ public void run() {
// That's our signal to stop
break;
} catch (Exception e) {
logger.warn("Error while polling/sending message", e);
logger.warn("Error while polling/sending message for {}", deviceId, e);
}
}
closeSocket();
logger.debug("Finished Mi IO MessageSenderThread");
logger.debug("Finished Mi IO MessageSenderThread {}", deviceId);
}
}

Expand Down