java - How many threads should I create in my case? -


i searched in google solution i'm still bit confused how many threads should use in particular case.

i have 2 usages of threads. first, have folder 10 files in want parse in parallel (independent of each other). second, have shared data object on 100 tasks run. each tasks consists of reading data object , writing shared structure (hashmap).

should use many threads cpu cores? or should use threadpoolexecutor minimum number of threads equals 2 , maximum number equals 999 (then 100 threads created)?

consider use of executors.newcachedthreadpool(). creates thread pool many threads needed , reuse idle threads.

i can't tell how many threads created 100 tasks. if task long execute, 100 threads created start tasks in parallel immediatly. if task short or if don't push tasks @ same moment, first thread reused executing more tasks (and not one).

by way, creating thread implies cost (cpu , memory) , many threads can useless due limitation of number of cores. in case, can limit number of threads using executors.newfixedthreadpool( int nthreads ).

a widespread practice use of number of cores x 2 thread count


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -