java - SingleThreadExecutor and ThreadFactory -
am right every time, when performing several submit operations:
executorservice executor = executors.newsinglethreadexecutor( new mythreadfactory("someexecutor")); executor.submit(...); executor.submit(...); executor.submit(...);
method java.util.concurrent.threadfactory#newthread
executes once? or executes every time , creates new thread per submit call?
it reuses same thread everytime.
that beauty of thread pools: avoid cost of creating new thread reducing per-task invocation overhead.
you can read more how threads created in threadpoolexecutor
documentation.
Comments
Post a Comment