mirror of
https://github.com/Dark98/SliceBeam.git
synced 2026-07-02 16:49:02 +00:00
Schedule truetime as non-critical task
This commit is contained in:
@@ -22,7 +22,17 @@ public class AppBoot {
|
||||
public static void run(List<BootTask> tasks) {
|
||||
long start = System.currentTimeMillis();
|
||||
AppBoot.tasks = tasks;
|
||||
AppBoot.latch = new CountDownLatch(tasks.size());
|
||||
int size = tasks.size();
|
||||
for (int i = 0, s = tasks.size(); i < s; i++) {
|
||||
BootTask task = tasks.get(i);
|
||||
if (task.nonCritical) {
|
||||
if (!task.workerThread) {
|
||||
throw new IllegalArgumentException("Can't schedule non-critical task on main thread");
|
||||
}
|
||||
size--;
|
||||
}
|
||||
}
|
||||
AppBoot.latch = new CountDownLatch(size);
|
||||
|
||||
for (int i = 0, s = tasks.size(); i < s; i++) {
|
||||
BootTask task = tasks.get(i);
|
||||
@@ -40,14 +50,21 @@ public class AppBoot {
|
||||
}
|
||||
}
|
||||
Log.d("boot", "Boot in " + (System.currentTimeMillis() - start) + "ms");
|
||||
tryShutdown();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void tryShutdown() {
|
||||
if (completed.size() == tasks.size()) {
|
||||
executor.shutdown();
|
||||
executor = null;
|
||||
tasks = null;
|
||||
pendingMain = null;
|
||||
pendingTasks = null;
|
||||
completed = null;
|
||||
latch = null;
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +74,11 @@ public class AppBoot {
|
||||
executor.submit(() -> {
|
||||
task.run.run();
|
||||
completed.put(task.index, true);
|
||||
latch.countDown();
|
||||
if (!task.nonCritical) {
|
||||
latch.countDown();
|
||||
} else {
|
||||
tryShutdown();
|
||||
}
|
||||
|
||||
if (!isContinue) {
|
||||
continueTasks(fromMain);
|
||||
@@ -67,7 +88,11 @@ public class AppBoot {
|
||||
Runnable r = () -> {
|
||||
task.run.run();
|
||||
completed.put(task.index, true);
|
||||
latch.countDown();
|
||||
if (!task.nonCritical) {
|
||||
latch.countDown();
|
||||
} else {
|
||||
tryShutdown();
|
||||
}
|
||||
|
||||
if (!isContinue) {
|
||||
continueTasks(fromMain);
|
||||
|
||||
@@ -8,6 +8,7 @@ public class BootTask {
|
||||
public final Runnable run;
|
||||
public boolean workerThread;
|
||||
public int priority;
|
||||
public boolean nonCritical;
|
||||
|
||||
/* package */ int index;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ public class ClearModelCacheTask extends BootTask {
|
||||
}
|
||||
}
|
||||
});
|
||||
nonCritical = true;
|
||||
onWorker();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ public class CloudInitTask extends BootTask {
|
||||
public CloudInitTask() {
|
||||
super(Arrays.asList(PrefsTask.class, TrueTimeTask.class, LoadSlic3rConfigTask.class), CloudController::init);
|
||||
onWorker();
|
||||
nonCritical = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ public class TrueTimeTask extends BootTask {
|
||||
super(() -> {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
try {
|
||||
TrueTime.build().withNtpHost("1.ru.pool.ntp.org").initialize();
|
||||
TrueTime.build().withNtpHost("1.ru.pool.ntp.org").withConnectionTimeout(300).initialize();
|
||||
break;
|
||||
} catch (IOException ignore) {
|
||||
try {
|
||||
@@ -19,5 +19,6 @@ public class TrueTimeTask extends BootTask {
|
||||
}
|
||||
});
|
||||
onWorker();
|
||||
nonCritical = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user