Customize thread creation
This commit is contained in:
parent
ee40ac5826
commit
ef40c04877
3 changed files with 28 additions and 5 deletions
|
@ -72,14 +72,26 @@ public final class Engine implements SubsystemMainClass {
|
|||
@Getter
|
||||
private static Engine instance = null;
|
||||
|
||||
/**
|
||||
* Contains the thread group of the engine.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*
|
||||
* -- GETTER --
|
||||
* Returns the thread group of the engine.
|
||||
*
|
||||
* @return engine thread group
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
@Getter
|
||||
private static final ThreadGroup threadGroup = new ThreadGroup("sos!engine");
|
||||
|
||||
/**
|
||||
* Logger instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NotNull
|
||||
private LoggerInstance logger;
|
||||
|
||||
/**
|
||||
|
|
|
@ -168,7 +168,10 @@ public class EventHelper {
|
|||
};
|
||||
|
||||
if (EngineConfiguration.getInstance().isOptimizeEvents())
|
||||
Thread.ofVirtual().start(eventCode);
|
||||
Thread
|
||||
.ofVirtual()
|
||||
.name("Event " + event.getName() + "[" + arguments + "]")
|
||||
.start(eventCode);
|
||||
else
|
||||
eventCode.run();
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ public final class Logger {
|
|||
public static void startLoggingThread() {
|
||||
if (loggingThread == null) {
|
||||
// Logging thread not defined, create and start new one
|
||||
loggingThread = Thread.ofPlatform().start(() -> {
|
||||
Runnable threadLogic = () -> {
|
||||
while (true) { // Run in loop
|
||||
// Stop thread when engine is shutting down
|
||||
if (Engine.getInstance().isShuttingDown())
|
||||
|
@ -144,7 +144,15 @@ public final class Logger {
|
|||
Thread.sleep(EngineConfiguration.getInstance().getLoggerPollingSpeed());
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
loggingThread = Thread
|
||||
.ofPlatform()
|
||||
.daemon()
|
||||
.name("Logging thread")
|
||||
.group(Engine.getThreadGroup())
|
||||
.stackSize(10)
|
||||
.start(threadLogic);
|
||||
} else {
|
||||
// Restart logging thread if dead
|
||||
if (!loggingThread.isAlive())
|
||||
|
|
Loading…
Reference in a new issue