adba
adba

Reputation: 497

How can I use SwingWorker safely?

I have just started to use SwingWorker for an iterative algorithm. After creating object of a class extended from SwingWorker, I performed the execute() function in the contructor function of my main class extended from JFrame. I use doInBackground() and process() functions during application runs. I don't need to stop the execution throughout the application. When user closes my JFrame application, do I need to carry out any stopping or cleaning task for SwingWorker? I mean, is it safe to close directly the JFrame application which uses SwingWorker?

Thanks

Upvotes: 1

Views: 56

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347332

SwingWorker uses it's own ExecutorService, which backed by it's own ThreadFactory which generates daemon Threads, meaning that the JVM will be able to exit once all the non-daemon thread's have finished.

Is it safe? That would come down to what it is your SwingWorker is actually doing, but if you're not holding any resources open or have other processes reliant on the result of the SwingWorker in order to completely their jobs (and close resources, etc), it should be

Upvotes: 3

Related Questions