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) {
|
public static void run(List<BootTask> tasks) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
AppBoot.tasks = tasks;
|
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++) {
|
for (int i = 0, s = tasks.size(); i < s; i++) {
|
||||||
BootTask task = tasks.get(i);
|
BootTask task = tasks.get(i);
|
||||||
@@ -40,14 +50,21 @@ public class AppBoot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d("boot", "Boot in " + (System.currentTimeMillis() - start) + "ms");
|
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.shutdown();
|
||||||
executor = null;
|
executor = null;
|
||||||
|
tasks = null;
|
||||||
pendingMain = null;
|
pendingMain = null;
|
||||||
pendingTasks = null;
|
pendingTasks = null;
|
||||||
completed = null;
|
completed = null;
|
||||||
latch = null;
|
latch = null;
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +74,11 @@ public class AppBoot {
|
|||||||
executor.submit(() -> {
|
executor.submit(() -> {
|
||||||
task.run.run();
|
task.run.run();
|
||||||
completed.put(task.index, true);
|
completed.put(task.index, true);
|
||||||
latch.countDown();
|
if (!task.nonCritical) {
|
||||||
|
latch.countDown();
|
||||||
|
} else {
|
||||||
|
tryShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
if (!isContinue) {
|
if (!isContinue) {
|
||||||
continueTasks(fromMain);
|
continueTasks(fromMain);
|
||||||
@@ -67,7 +88,11 @@ public class AppBoot {
|
|||||||
Runnable r = () -> {
|
Runnable r = () -> {
|
||||||
task.run.run();
|
task.run.run();
|
||||||
completed.put(task.index, true);
|
completed.put(task.index, true);
|
||||||
latch.countDown();
|
if (!task.nonCritical) {
|
||||||
|
latch.countDown();
|
||||||
|
} else {
|
||||||
|
tryShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
if (!isContinue) {
|
if (!isContinue) {
|
||||||
continueTasks(fromMain);
|
continueTasks(fromMain);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public class BootTask {
|
|||||||
public final Runnable run;
|
public final Runnable run;
|
||||||
public boolean workerThread;
|
public boolean workerThread;
|
||||||
public int priority;
|
public int priority;
|
||||||
|
public boolean nonCritical;
|
||||||
|
|
||||||
/* package */ int index;
|
/* package */ int index;
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class ClearModelCacheTask extends BootTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
nonCritical = true;
|
||||||
onWorker();
|
onWorker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ public class CloudInitTask extends BootTask {
|
|||||||
public CloudInitTask() {
|
public CloudInitTask() {
|
||||||
super(Arrays.asList(PrefsTask.class, TrueTimeTask.class, LoadSlic3rConfigTask.class), CloudController::init);
|
super(Arrays.asList(PrefsTask.class, TrueTimeTask.class, LoadSlic3rConfigTask.class), CloudController::init);
|
||||||
onWorker();
|
onWorker();
|
||||||
|
nonCritical = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class TrueTimeTask extends BootTask {
|
|||||||
super(() -> {
|
super(() -> {
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
try {
|
try {
|
||||||
TrueTime.build().withNtpHost("1.ru.pool.ntp.org").initialize();
|
TrueTime.build().withNtpHost("1.ru.pool.ntp.org").withConnectionTimeout(300).initialize();
|
||||||
break;
|
break;
|
||||||
} catch (IOException ignore) {
|
} catch (IOException ignore) {
|
||||||
try {
|
try {
|
||||||
@@ -19,5 +19,6 @@ public class TrueTimeTask extends BootTask {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
onWorker();
|
onWorker();
|
||||||
|
nonCritical = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user