From cfe39d72f940dbab8605f81ade21bea99a8c1687 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Wed, 24 Jan 2018 20:30:45 -0500 Subject: [PATCH] docs & better field name --- .../io/src/com/rusefi/io/LinkManager.java | 24 ++++++++++++++++++- .../io/src/com/rusefi/io/tcp/TcpIoStream.java | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/java_console/io/src/com/rusefi/io/LinkManager.java b/java_console/io/src/com/rusefi/io/LinkManager.java index 9960e8c77a..b7ba4f3ca0 100644 --- a/java_console/io/src/com/rusefi/io/LinkManager.java +++ b/java_console/io/src/com/rusefi/io/LinkManager.java @@ -59,7 +59,12 @@ public class LinkManager { } }; - public final static Executor IO_EXECUTOR = Executors.newSingleThreadExecutor(new ThreadFactory() { + /** + * Threading of the whole input/output does not look healthy at all! + * + * @see #COMMUNICATION_EXECUTOR + */ + public final static Executor TCP_READ_EXECUTOR = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override public Thread newThread(@NotNull Runnable r) { Thread t = new Thread(r); @@ -72,6 +77,7 @@ public class LinkManager { public static final LinkedBlockingQueue COMMUNICATION_QUEUE = new LinkedBlockingQueue<>(); /** * All request/responses to underlying controller are happening on this single-threaded executor in a FIFO manner + * @see #TCP_READ_EXECUTOR */ public static final ExecutorService COMMUNICATION_EXECUTOR = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, @@ -85,6 +91,22 @@ public class LinkManager { return t; } }); + private static Thread COMMUNICATION_THREAD; + + static { + COMMUNICATION_EXECUTOR.submit(new Runnable() { + @Override + public void run() { + COMMUNICATION_THREAD = Thread.currentThread(); + } + }); + } + + public static void assertCommunicationThread() { +// if (Thread.currentThread() != COMMUNICATION_THREAD) +// throw new IllegalStateException("Communication on wrong thread"); + } + public static EngineState engineState = new EngineState(new EngineState.EngineStateListenerImpl() { @Override public void beforeLine(String fullLine) { diff --git a/java_console/io/src/com/rusefi/io/tcp/TcpIoStream.java b/java_console/io/src/com/rusefi/io/tcp/TcpIoStream.java index 9d26528369..87f4474672 100644 --- a/java_console/io/src/com/rusefi/io/tcp/TcpIoStream.java +++ b/java_console/io/src/com/rusefi/io/tcp/TcpIoStream.java @@ -45,7 +45,7 @@ public class TcpIoStream implements IoStream { @Override public void setInputListener(final DataListener listener) { - LinkManager.IO_EXECUTOR.execute(new Runnable() { + LinkManager.TCP_READ_EXECUTOR.execute(new Runnable() { @Override public void run() { Thread.currentThread().setName("TCP connector loop");