Code:
//List all threads:
Set<Thread> runningThreads = Thread.getAllStackTraces().keySet();
System.out.println(runningThreads.toString());
//Thread creation:
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.execute(this);
//Thread termination:
executorService.shutdownNow();
//List all threads:
Set<Thread> runningThreads = Thread.getAllStackTraces().keySet();
System.out.println(runningThreads.toString());
I would expect the list that gets printed out to be exactly the same both times but what I'm getting is a print out of the thread that was created included in the results
How do I completely destroy a thread so that it's nowhere to be found?