mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
initSystems now uses latch instead of timer. Moved single threads to Executor
This commit is contained in:
@@ -33,6 +33,9 @@ import javafx.scene.layout.StackPane;
|
|||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public final class App extends Application {
|
public final class App extends Application {
|
||||||
private static Stage stage;
|
private static Stage stage;
|
||||||
@@ -46,7 +49,7 @@ public final class App extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws Exception {
|
public void start(Stage stage) {
|
||||||
// Start loading localization
|
// Start loading localization
|
||||||
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/localization"));
|
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/localization"));
|
||||||
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/style"));
|
ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/style"));
|
||||||
@@ -180,12 +183,20 @@ public final class App extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initSystems() { // TODO Move to better place
|
private void initSystems() { // TODO Move to better place
|
||||||
new Thread(() -> new NetworkingClientEventListener(
|
|
||||||
GlobalEventBus.get(),
|
|
||||||
new NetworkingClientManager(GlobalEventBus.get()))
|
|
||||||
).start();
|
|
||||||
|
|
||||||
new Thread(() -> {
|
final int THREAD_COUNT = 2;
|
||||||
|
CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
|
||||||
|
ExecutorService threads = Executors.newFixedThreadPool(THREAD_COUNT);
|
||||||
|
|
||||||
|
threads.submit(() -> {
|
||||||
|
new NetworkingClientEventListener(
|
||||||
|
GlobalEventBus.get(),
|
||||||
|
new NetworkingClientManager(GlobalEventBus.get()));
|
||||||
|
|
||||||
|
latch.countDown();
|
||||||
|
});
|
||||||
|
|
||||||
|
threads.submit(() -> {
|
||||||
MusicManager<MusicAsset> musicManager =
|
MusicManager<MusicAsset> musicManager =
|
||||||
new MusicManager<>(
|
new MusicManager<>(
|
||||||
GlobalEventBus.get(),
|
GlobalEventBus.get(),
|
||||||
@@ -209,11 +220,11 @@ public final class App extends Application {
|
|||||||
audioVolumeManager
|
audioVolumeManager
|
||||||
).initListeners("medium-button-click.wav");
|
).initListeners("medium-button-click.wav");
|
||||||
|
|
||||||
}).start();
|
latch.countDown();
|
||||||
|
});
|
||||||
|
|
||||||
// Threads must be ready, before continue, TODO use latch instead
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(200);
|
latch.await();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user