Use platform threads in development mode instead of virtual ones

This commit is contained in:
crschnick 2023-08-03 18:30:46 +00:00
parent 454e8aea75
commit 8c4c68f24a
10 changed files with 24 additions and 22 deletions

View file

@ -142,6 +142,7 @@ application {
}
run {
systemProperty 'io.xpipe.app.useVirtualThreads', 'false'
systemProperty 'io.xpipe.app.mode', 'gui'
systemProperty 'io.xpipe.app.dataDir', "$projectDir/local7/"
systemProperty 'io.xpipe.app.writeLogs', "true"

View file

@ -56,7 +56,7 @@ public class AppFileWatcher {
}
active = true;
watcherThread = ThreadHelper.create("file watcher", true, () -> {
watcherThread = ThreadHelper.createPlatformThread("file watcher", true, () -> {
while (active) {
WatchKey key;
try {

View file

@ -53,7 +53,7 @@ public class AppMainWindow {
private synchronized void onChange() {
lastUpdate = Instant.now();
if (thread == null) {
thread = ThreadHelper.create("window change timeout", true, () -> {
thread = ThreadHelper.createPlatformThread("window change timeout", true, () -> {
while (true) {
var toStop = lastUpdate.plus(Duration.of(1, ChronoUnit.SECONDS));
if (Instant.now().isBefore(toStop)) {

View file

@ -21,14 +21,17 @@ public class AppProperties {
private static final String EXTENSION_PATHS_PROP = "io.xpipe.app.extensions";
private static AppProperties INSTANCE;
boolean fullVersion;
@Getter
String version;
@Getter
String build;
UUID buildUuid;
String sentryUrl;
String arch;
@Getter
boolean image;
boolean staging;
@Getter
boolean useVirtualThreads;
Path dataDir;
boolean showcase;
@ -48,6 +51,9 @@ public class AppProperties {
staging = Optional.ofNullable(System.getProperty("io.xpipe.app.staging"))
.map(Boolean::parseBoolean)
.orElse(false);
useVirtualThreads = Optional.ofNullable(System.getProperty("io.xpipe.app.useVirtualThreads"))
.map(Boolean::parseBoolean)
.orElse(true);
dataDir = parseDataDir();
showcase = Optional.ofNullable(System.getProperty("io.xpipe.app.showcase"))
.map(Boolean::parseBoolean)
@ -106,10 +112,6 @@ public class AppProperties {
return Path.of(System.getProperty("user.home"), isStaging() ? ".xpipe_stage" : ".xpipe");
}
public String getVersion() {
return version;
}
public boolean isDeveloperMode() {
if (AppPrefs.get() == null) {
return false;
@ -118,11 +120,4 @@ public class AppProperties {
return AppPrefs.get().developerMode().getValue();
}
public boolean isImage() {
return image;
}
public String getBuild() {
return build;
}
}

View file

@ -122,7 +122,7 @@ public abstract class OperationMode {
}
public static void switchToAsync(OperationMode newMode) {
ThreadHelper.create("mode switcher", false, () -> switchTo(newMode)).start();
ThreadHelper.createPlatformThread("mode switcher", false, () -> switchTo(newMode)).start();
}
public static void switchTo(OperationMode newMode) {

View file

@ -40,7 +40,7 @@ public abstract class PlatformMode extends OperationMode {
TrackEvent.info("mode", "Finished essential component initialization before platform");
TrackEvent.info("mode", "Launching application ...");
ThreadHelper.create("app", false, () -> {
ThreadHelper.createPlatformThread("app", false, () -> {
TrackEvent.info("mode", "Application thread started");
Application.launch(App.class);
})

View file

@ -43,7 +43,7 @@ public class BindingsHelper {
}
static {
ThreadHelper.create("referenceGC", true, () -> {
ThreadHelper.createPlatformThread("referenceGC", true, () -> {
while (true) {
for (ReferenceEntry reference : REFERENCES) {
if (reference.canGc()) {

View file

@ -89,7 +89,7 @@ public abstract class UpdateHandler {
}
private void startBackgroundUpdater() {
ThreadHelper.create("updater", true, () -> {
ThreadHelper.createPlatformThread("updater", true, () -> {
ThreadHelper.sleep(Duration.ofMinutes(5).toMillis());
event("Starting background updater thread");
while (true) {

View file

@ -1,19 +1,24 @@
package io.xpipe.app.util;
import io.xpipe.app.core.AppProperties;
import io.xpipe.app.issue.ErrorEvent;
import org.apache.commons.lang3.function.FailableRunnable;
public class ThreadHelper {
private static Thread unstarted(Runnable r) {
return AppProperties.get().isUseVirtualThreads() ? Thread.ofVirtual().unstarted(r) : Thread.ofPlatform().unstarted(r);
}
public static Thread runAsync(Runnable r) {
var t = Thread.ofVirtual().unstarted(r);
var t = unstarted(r);
t.setDaemon(true);
t.start();
return t;
}
public static Thread runFailableAsync(FailableRunnable<Throwable> r) {
var t = Thread.ofVirtual().unstarted(() -> {
var t = unstarted(() -> {
try {
r.run();
} catch (Throwable e) {
@ -25,7 +30,7 @@ public class ThreadHelper {
return t;
}
public static Thread create(String name, boolean daemon, Runnable r) {
public static Thread createPlatformThread(String name, boolean daemon, Runnable r) {
var t = new Thread(r);
t.setDaemon(daemon);
t.setName(name);

View file

@ -2,4 +2,5 @@
-Dio.xpipe.app.writeLogs=false
-Dio.xpipe.app.logLevel=trace
-Dio.xpipe.app.developerMode=true
-Dio.xpipe.beacon.debugOutput=true
-Dio.xpipe.beacon.debugOutput=true
-Dio.xpipe.app.useVirtualThreads=false