Skip to content

Commit

Permalink
Use new thread builders
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Feb 19, 2024
1 parent 8c07590 commit c5b101b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultCaret;
import javax.swing.text.Document;
import javax.swing.text.DocumentFilter;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.pistonmaster.soulfire.server.util.XtermPalette256;
Expand Down Expand Up @@ -76,7 +76,7 @@ public class MessageLogPanel extends JPanel {
private final NoopDocumentFilter noopDocumentFilter = new NoopDocumentFilter();
private final List<String> toInsert = Collections.synchronizedList(new ArrayList<>());
private final JTextPane textComponent;
private final StyledDocument document;
private final Document document;
private final ParserFactory factory =
new DefaultParserFactory.Builder()
.environment(Environment._7_BIT)
Expand All @@ -103,7 +103,7 @@ public MessageLogPanel(int numLines) {

var caret = (DefaultCaret) textComponent.getCaret();
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
document = textComponent.getStyledDocument();
document = textComponent.getDocument();
document.addDocumentListener(new LimitLinesDocumentListener(numLines, true));
((AbstractDocument) document).setDocumentFilter(noopDocumentFilter);

Expand All @@ -122,12 +122,7 @@ public MessageLogPanel(int numLines) {

var executorService =
Executors.newSingleThreadScheduledExecutor(
(r) -> {
var thread = new Thread(r);
thread.setName("MessageLogPanel");
thread.setDaemon(true);
return thread;
});
r -> Thread.ofPlatform().name("MessageLogPanel").daemon().unstarted(r));
executorService.scheduleWithFixedDelay(
this::updateTextComponent, 100, 100, TimeUnit.MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ public ExecutorService newCachedExecutorService(BotConnection botConnection, Str

private ThreadFactory getThreadFactory(BotConnection botConnection, String threadName) {
return runnable -> {
var thread =
new Thread(
() -> {
BOT_CONNECTION_THREAD_LOCAL.set(botConnection);
runnable.run();
BOT_CONNECTION_THREAD_LOCAL.remove();
});
var usedThreadName = threadName;
if (runnable instanceof NamedRunnable named) {
usedThreadName = named.name();
}
thread.setName(threadPrefix + "-" + usedThreadName);

return thread;
return Thread.ofPlatform()
.name(threadPrefix + "-" + usedThreadName)
.daemon()
.unstarted(
() -> {
BOT_CONNECTION_THREAD_LOCAL.set(botConnection);
runnable.run();
BOT_CONNECTION_THREAD_LOCAL.remove();
});
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public class SFNettyHelper {
private SFNettyHelper() {}

public static EventLoopGroup createEventLoopGroup(int threads, String name) {
ThreadFactory threadFactory = r -> new Thread(r, "SoulFire-" + name);
ThreadFactory threadFactory =
r -> Thread.ofPlatform().name(name).daemon().priority(Thread.MAX_PRIORITY).unstarted(r);
EventLoopGroup group =
switch (TransportHelper.determineTransportMethod()) {
case IO_URING -> new IOUringEventLoopGroup(threads, threadFactory);
Expand Down

0 comments on commit c5b101b

Please sign in to comment.