How to kill all/particular background thread in Javafx?

1.4k views Asked by At

The application is having four javafx fxml-screens : login, home, profile and features. A lots of worker thread is created in various screens after login is done. When user is getting logout, the all worker thread except Javafx-Application-Thread should be cancelled.

2

There are 2 answers

0
Maulik Patel On

There is not any mechanism for kill any thread in javafx.
but y can cancel the particular thread using cancel() method.

0
Salah Eddine Taouririt On

A convenient way to manage your worker threads is to use the Executor framework.

Example:

ExecutorService executorService = Executors.newFixedThreadPool(2);

//  submit your JavaFX tasks and services 
executorService.shutdown();
//executorService.shutdownNow();

More about Java and JavaFX concurrency: