Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) Add check to cleanup for active FX Application Thread. #288

Merged
merged 2 commits into from
Jun 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}

}