It depends on how you want the 10 threads to be “completed” and how you execute the threads.
I recommend creating an ExecutorService and writing your "threads" as Runnable . These Runnable objects must respond to interrupt() calls in their execution thread, interrupting their task, clearing and exiting run as quickly as possible.
Submit these Runnable tasks to the ExecutorService , then call awaitTermination , all in the main topic. When the user clicks the Stop button, call shutdown or shutdownNow as desired on the ExecutorService (from the event dispatch stream).
If you call shutdownNow in the executor’s service, it will notify the tasks in progress, interrupting their threads. If you call shutdown , this will allow you to complete tasks without interruption. No matter what, your main thread will block on awaitTermination until all tasks complete (or expire).
You can, of course, create and manage all threads yourself using join . The key is to make threads intermittent if you want to stop them prematurely.
source share