Skip to content

Commit

Permalink
Merge pull request #288 from Ortner/dev_application_stop_hangup
Browse files Browse the repository at this point in the history
(fix) Add check to cleanup for active FX Application Thread.
  • Loading branch information
hastebrot committed Jun 30, 2016
2 parents bf54605 + f366165 commit d066512
Showing 1 changed file with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,21 @@ public static Application setupApplication(Supplier<Application> applicationSupp
);
}

/**
* Performs the clean up of the application. This is done by calling {@link ToolkitService#cleanupApplication(Application)}
* (which usually calls the {@code stop} method of the application).
* @param application the application to clean up
* @throws TimeoutException if cleanup is not finished before {@link FxToolkitContext#getSetupTimeoutInMillis()}
* or the FX Application Thread is not running
*/
@Unstable(reason = "is missing apidocs")
public static void cleanupApplication(Application application)
throws TimeoutException {
waitForSetup(
service.cleanupApplication(application)
);
if(isFXApplicationThreadRunning()){
waitForSetup(service.cleanupApplication(application));
}else{
throw new TimeoutException("FX Application Thread not running");
}
}

@Unstable(reason = "is missing apidocs")
Expand Down Expand Up @@ -292,4 +301,16 @@ private static void preventShutdownWhenLastWindowIsClosed() {
Platform.setImplicitExit(false);
}

/**
* Detects if the JavaFx Application Thread is currently running.
* @return true, if the FX Application Thread is running
*/
private static boolean isFXApplicationThreadRunning(){
Set<Thread> threads=Thread.getAllStackTraces().keySet();
for(Thread thread:threads){
if(thread.getName().equals("JavaFX Application Thread"))return true;
}
return false;
}

}

0 comments on commit d066512

Please sign in to comment.