I have a code block
for (i=0;i<size;i++) { do job; } initially this job task was executed sequentially (as shown above) but later I made multithreaded with normal threads (inner runnable class implementation) like,
for (i=0;i<size;i++) { new threadingclass(some args) } runnable threadingclass { pub void run () { do job; } } this worked fine with some thread limit (till system resources were enough) so to avoid resource overloading I implemented same code with standard theadpool implementation (threadpool,executor service and worker thread implementation)
threadexecutor t=new threadexecutor(size) for (i=0 ; i<size ; i++) { t.execute(new threadingclass(some args)) } runnable threadingclass { pub void run () { do job; } } now scenario was like,
I wanted to run loop for 25 times (no. of threads), I tried with all 3 implementations
- sequential : takes 7 min approx
- normal multithreading : 40 sec
- multithreading with threadpool (size : 100) : 2 min approx
I am bit confused why normal threading and thredpool implementation timings differ so much and internally also threadpool does not involve much complex logic. any help is appreciated.
Thanks in advance
-Xprofoption for the built-in profiler.threadexecutor? Did you try using the JVM-Classes instead of your own?Runtime.getRuntime().availableProcessors()threads. Also: What kind of Executor did you create?