Java multithreading - 6 threads or 30 threads? -


this question has answer here:

i'm working on multithreaded application needs perform optical character recognition. requirement of app must work really, fast.

at 1 time, have simultaneously read 6 different words. i'm doing is, starting 6 threads, 1 thread dedicated reading each word.

however, i'm wondering if should go further, , start 1 thread each character within word. e.g, if have 6 words , each word has 5-6 characters, mean 30-36 threads (possibly upto 50-70 threads longer words).

to process each individual character, seems take between 10-30 milliseconds, total of 200-300 milliseconds per word. (i need bring down 100 milliseconds or less per word).

which strategy give me better performance? 1 thread per word, or 1 thread per character?

which strategy give me better performance? 1 thread per word, or 1 thread per character?

the answer highly dependent on hardware architecture , processing being done. processing completely cpu bound or there logging or other io? best way answer performance runs trying various different thread settings number of trials see 1 better. accurate results, test runs should longer couple of seconds rule out jit , other java initialization.

couple other thoughts:

  • as mentioned @sotirios , others, throwing more threads @ problem may run slower because of context switching overhead.

  • you should use executorservice thread-pool not forking , reaping threads every time. thread startup/shutdown not insignificant process.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -