GC after game launched
This commit is contained in:
@@ -40,7 +40,7 @@ public class AuthlibInjectorAccount extends YggdrasilAccount {
|
||||
Arguments arguments = Arguments.addJVMArguments(null, arg);
|
||||
|
||||
if (flag.get())
|
||||
arguments = Arguments.addJVMArguments(arguments, "-Dorg.to2mbn.authlibinjector.config.prefetched=" + getTask.getResult());
|
||||
arguments = Arguments.addJVMArguments(arguments, "-Dorg.to2mbn.authlibinjector.config.prefetched=" + new String(Base64.getEncoder().encode(getTask.getResult().getBytes())));
|
||||
|
||||
return info.setArguments(arguments);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -166,7 +166,7 @@ public class YggdrasilAccount extends Account {
|
||||
isOnline = true;
|
||||
return;
|
||||
}
|
||||
logIn1(routeRefresh, new RefreshRequest(accessToken, clientToken), proxy);
|
||||
logIn1(routeRefresh, new RefreshRequest(accessToken, clientToken, getSelectedProfile()), proxy);
|
||||
}
|
||||
|
||||
public void logInWithPassword0(String password, Proxy proxy) throws AuthenticationException {
|
||||
|
||||
@@ -208,9 +208,9 @@ public abstract class Task {
|
||||
return new TaskExecutor(this);
|
||||
}
|
||||
|
||||
public final TaskExecutor executor(Function<TaskExecutor, TaskListener> taskListener) {
|
||||
public final TaskExecutor executor(TaskListener taskListener) {
|
||||
TaskExecutor executor = new TaskExecutor(this);
|
||||
executor.addTaskListener(taskListener.apply(executor));
|
||||
executor.addTaskListener(taskListener);
|
||||
return executor;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,13 +66,8 @@ public final class TaskExecutor {
|
||||
public TaskExecutor start() {
|
||||
taskListeners.forEach(TaskListener::onStart);
|
||||
workerQueue.add(scheduler.schedule(() -> {
|
||||
if (executeTasks(Collections.singleton(firstTask)))
|
||||
taskListeners.forEach(TaskListener::onSucceed);
|
||||
else
|
||||
taskListeners.forEach(it -> {
|
||||
it.onTerminate();
|
||||
it.onTerminate(variables);
|
||||
});
|
||||
boolean flag = executeTasks(Collections.singleton(firstTask));
|
||||
taskListeners.forEach(it -> it.onStop(flag, this));
|
||||
}));
|
||||
return this;
|
||||
}
|
||||
@@ -81,14 +76,8 @@ public final class TaskExecutor {
|
||||
taskListeners.forEach(TaskListener::onStart);
|
||||
AtomicBoolean flag = new AtomicBoolean(true);
|
||||
Future<?> future = scheduler.schedule(() -> {
|
||||
if (!executeTasks(Collections.singleton(firstTask))) {
|
||||
taskListeners.forEach(it -> {
|
||||
it.onTerminate();
|
||||
it.onTerminate(variables);
|
||||
});
|
||||
flag.set(false);
|
||||
} else
|
||||
taskListeners.forEach(TaskListener::onSucceed);
|
||||
flag.set(executeTasks(Collections.singleton(firstTask)));
|
||||
taskListeners.forEach(it -> it.onStop(flag.get(), this));
|
||||
});
|
||||
workerQueue.add(future);
|
||||
Lang.invoke(() -> future.get());
|
||||
@@ -207,6 +196,10 @@ public final class TaskExecutor {
|
||||
return totTask.get();
|
||||
}
|
||||
|
||||
public AutoTypingMap<String> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
|
||||
private class Invoker implements ExceptionalRunnable<Exception> {
|
||||
|
||||
private final Task task;
|
||||
|
||||
@@ -39,16 +39,12 @@ public abstract class TaskListener implements EventListener {
|
||||
public void onFailed(Task task, Throwable throwable) {
|
||||
}
|
||||
|
||||
public void onTerminate() {
|
||||
}
|
||||
|
||||
public void onTerminate(AutoTypingMap<String> variables) {
|
||||
}
|
||||
|
||||
public void onSucceed() {
|
||||
public void onStop(boolean success, TaskExecutor executor) {
|
||||
}
|
||||
|
||||
public static class DefaultTaskListener extends TaskListener {
|
||||
private DefaultTaskListener() {
|
||||
}
|
||||
|
||||
public static final DefaultTaskListener INSTANCE = new DefaultTaskListener();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jackhuang.hmcl.util;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -249,6 +250,17 @@ public final class Lang {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void executeDelayed(Runnable runnable, TimeUnit timeUnit, long timeout, boolean isDaemon) {
|
||||
thread(() -> {
|
||||
try {
|
||||
timeUnit.sleep(timeout);
|
||||
runnable.run();
|
||||
} catch (InterruptedException ignore) {
|
||||
}
|
||||
|
||||
}, null, isDaemon);
|
||||
}
|
||||
|
||||
public static Thread thread(Runnable runnable) {
|
||||
return thread(runnable, null);
|
||||
}
|
||||
|
||||
@@ -122,4 +122,10 @@ public enum OperatingSystem {
|
||||
c.putString(string);
|
||||
Clipboard.getSystemClipboard().setContent(c);
|
||||
}
|
||||
|
||||
public static void forceGC() {
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user