rusefi 2022-05-16 10:08:39 -04:00
parent d917037d06
commit 122d224451
2 changed files with 28 additions and 4 deletions

View File

@ -405,8 +405,8 @@ public final class SerialPort
catch (Exception e) { e.printStackTrace(); }
// Add a shutdown hook to ensure that all ports get closed
Runtime.getRuntime().addShutdownHook(new Thread()
{
Runtime.getRuntime().addShutdownHook(SerialPortThreadFactory.get().newThread(new Runnable() {
@Override
public void run()
{
// Run any user-specified shutdown hooks
@ -423,7 +423,7 @@ public final class SerialPort
isShuttingDown = true;
uninitializeLibrary();
}
});
}));
}
// Static symbolic link testing function
@ -1755,7 +1755,7 @@ public final class SerialPort
dataPacketIndex = 0;
setEventListeningStatus(portHandle, true);
serialEventThread = new Thread(new Runnable()
serialEventThread = SerialPortThreadFactory.get().newThread(new Runnable()
{
@Override
public void run()

View File

@ -0,0 +1,24 @@
package com.fazecast.jSerialComm;
import java.util.concurrent.ThreadFactory;
public class SerialPortThreadFactory {
private static ThreadFactory INSTANCE = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r);
}
};
public static ThreadFactory get() {
return INSTANCE;
}
/**
* Use this method to supply custom thread factory
* @param threadFactory
*/
public static void set(ThreadFactory threadFactory) {
SerialPortThreadFactory.INSTANCE = threadFactory;
}
}