mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-10-08 08:01:39 +00:00
Add threading debug
This commit is contained in:
1 parent
b1f5c0549c
commit
ce32613dd4
3 files changed
+22
-11
No files matched your search
@@ -30,6 +30,7 @@ public class AppProperties {
|
||||
boolean image;
|
||||
boolean staging;
|
||||
boolean useVirtualThreads;
|
||||
boolean debugThreads;
|
||||
Path dataDir;
|
||||
boolean showcase;
|
||||
|
||||
@@ -50,6 +51,9 @@ public class AppProperties {
|
||||
useVirtualThreads = Optional.ofNullable(System.getProperty("io.xpipe.app.useVirtualThreads"))
|
||||
.map(Boolean::parseBoolean)
|
||||
.orElse(true);
|
||||
debugThreads = Optional.ofNullable(System.getProperty("io.xpipe.app.debugThreads"))
|
||||
.map(Boolean::parseBoolean)
|
||||
.orElse(false);
|
||||
dataDir = XPipeInstallation.getDataDir();
|
||||
showcase = Optional.ofNullable(System.getProperty("io.xpipe.app.showcase"))
|
||||
.map(Boolean::parseBoolean)
|
||||
|
||||
@@ -2,22 +2,29 @@ package io.xpipe.app.util;
|
||||
|
||||
import io.xpipe.app.core.AppProperties;
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.issue.TrackEvent;
|
||||
import io.xpipe.core.util.FailableRunnable;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ThreadHelper {
|
||||
|
||||
public static Thread unstarted(Runnable r) {
|
||||
return AppProperties.get().isUseVirtualThreads() ? Thread.ofVirtual().unstarted(r) : Thread.ofPlatform().unstarted(r);
|
||||
private static final AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
private static Runnable wrap(Runnable r) {
|
||||
return () -> {
|
||||
if (AppProperties.get().isDebugThreads()) {
|
||||
TrackEvent.trace("Started. Active threads: " + counter.incrementAndGet());
|
||||
}
|
||||
r.run();
|
||||
if (AppProperties.get().isDebugThreads()) {
|
||||
TrackEvent.trace("Finished. Active threads: " + counter.decrementAndGet());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Thread unstartedFailable(FailableRunnable<Exception> r) {
|
||||
return unstarted(() -> {
|
||||
try {
|
||||
r.run();
|
||||
} catch (Throwable e) {
|
||||
ErrorEvent.fromThrowable(e).handle();
|
||||
}
|
||||
});
|
||||
public static Thread unstarted(Runnable r) {
|
||||
return AppProperties.get().isUseVirtualThreads() ? Thread.ofVirtual().unstarted(wrap(r)) : Thread.ofPlatform().unstarted(wrap(r));
|
||||
}
|
||||
|
||||
public static Thread runAsync(Runnable r) {
|
||||
|
||||
Reference in new issue
Block a user