java - How (in)efficient is ExecutorService.invokeAll() when called with a single task? -


i have code makes heavy use of thread pool, use creating collection<callable<t>> tasks, , calling executorservice.invokeall(tasks).

for (future<object> future : threadpool.invokeall(tasks)) {   object object = future.get();   // calling thread blocks on invokeall(). } 

in app, size of tasks varies lot. in fact, of time executorservice.invokeall() called single task. implementation of invokeall() i'm using calls threadpoolexecutor.execute(), whose implementation appears run task in thread pool (never in calling thread).

in case of single task, more efficient call task in current thread rather send off thread?

in case of single task, more efficient call task in current thread rather send off thread?

yes, more efficient. that's not interesting question though. interesting questions how inefficient - depend on task doing - , whether you're doing enough in application significant overall.

we don't have enough information evaluate you. if you're executing single trivial task ("fetch value map") millions of times per second, indirection via thread pool make real difference. if tasks actually significant amount of work, it's not worth code of special-casing case you've got single task.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -