android - number of active threads keeps increasing -


i using executorservice excecute 1 task @ time using code `

executorservice=executors.newsinglethreadexecutor(); 

and using thread.activecount() number of active threads whenever submit runnable task executorservice number of active threads incremented 1 ,how possible ? thought newsinglethreadexecutor() allows executing 1 task @ time , why number of threads keeps increasing? ,i mean shouldn't number of threads increases 1 , not more?

note using future cancel execution of runnable before submitting new task , works fine ,all runnables interrupted number of active threads keeps increasing.

edit: code call whenever press on button (worker class implements runnable)

private void handle() {     executorservice=executors.newsinglethreadexecutor();     worker worker=new worker();     future=executorservice.submit(new worker()); } 

each time call it cretes new executor. each single threaded executor has own thread. if want multiple jobs on executor call newsinglethreadedexecutor once , submit jobs executor. not call newsinglethreadedexecutor multiple times


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -