Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
l have a program where l extended swingworker in three classes. And l have a button to cancel. I used swingworker cancel
new swingWorkerClass().cancel
.
Am afraid if a user clicks cancel button, if it will cancel all other threads running at that particular instance of the application? That is, will it cancel every thread started even by other classes. If yes, how can l get and stop a particular thread?.

What I have tried:

new swingWorkerClasss().cancel
Posted
Updated 5-Aug-17 14:29pm

I read the documentation and understood that it stops only its own thread.
Canceling Background Tasks (The Java™ Tutorials > Creating a GUI With JFC/Swing > Concurrency in Swing)[^]
 
Share this answer
 
Generally speaking, having a main thread canceling child threads is a bad idea, anything that can go wrong will gp wrong, it is just a matter of time.
Because a thread canceling is authoritative and it happen no matter what is doing the thread, and there is no cleanup.
It is a better idea to design the thread in a way that let you send it a signal and let thread abort by itself which allow the thread to do all cleanup before aborting.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900