roskenet / springboot-javafx-support

SpringBoot / JavaFX8 Integration
MIT License
422 stars 139 forks source link

Concurrency Bug in AbstractJavaFxApplicationSupport #57

Closed Pyknic closed 6 years ago

Pyknic commented 6 years ago

In AbstractJavaFxApplicationSupport, there appears to be a concurrency issue. On line 166, there is a synchronize-statement that doesn't do anything unless multiple threads are invoking the start(Stage)-method at the same time. It doesn't prevent appCtxLoaded from being modified outside the synchronized block, which is the case in launchApplicationView.

synchronized (this) { // This does not prevent other threads from modifying appCtxLoaded from a different method!!
    if (appCtxLoaded.get()) { 
        // Spring ContextLoader was faster
        Platform.runLater(showMainAndCloseSplash);
    } else {
        appCtxLoaded.addListener((ov, oVal, nVal) -> {
            Platform.runLater(showMainAndCloseSplash);
        });
    }
}

The correct way of doing this would be to remove the synchronized-statement, change the BooleanProperty to a CompletableFuture that completes once the splash-message is showing and then close the splash once both the "splash is showing" and "context is loaded" conditions are satisfied.

roskenet commented 6 years ago

Yes, there are some known issues! Thanks for addressing this!