I use the executorService function to exclude only one task at a time using this code `
executorService=Executors.newSingleThreadExecutor();
and I use Thread.activeCount()to get the number of active threads, but every time I send a task to the executing service, the number of active threads increases by one, how is this possible? I thought that it newSingleThreadExecutor()allows you to perform only one task at a time, why does the number of threads continue to increase ?, I mean, should the number of threads increase by only one and no more?
Please note that I also use the future to cancel the execution of all runnable before even sending a new task, and it works fine, all runnables are interrupted, but the number of active threads continues to increase.
Edit: this is the code that I call whenever I click the button (Worker is just a class that implements runnable)
private void handle() {
executorService=Executors.newSingleThreadExecutor();
Worker worker=new Worker();
future=executorService.submit(new Worker());
}
has19 source
share