4
I am making a server in java wanted to perform certain tasks in parallel. I have a list of a certain type I want 20 threads to deal with elements of the list.
for( Item item : result ) {
Callable< List< IResult > > callable = new HTMLParser( item );
Future< List< IResult > > future = pool.submit( callable );
set.add( future );
}
for( Future< List< IResult > > future : set ) {
List< IResult > result = future.get( ); // wait for a processor to complete
if( result != null && !result.isEmpty( ) )
FResults.addAll( result );
}
}
Only running this hiccup, analyzing the logs seems to me to be running the threads sequentially
2016-12-06 14:17:02.106 DEBUG 18229 --- [pool-1-thread-5] ......
2016-12-06 14:17:02.106 DEBUG 18229 --- [pool-1-thread-5] ....
2016-12-06 14:17:02.106 DEBUG 18229 --- [pool-1-thread-5] .....
2016-12-06 14:17:02.106 DEBUG 18229 --- [pool-1-thread-5] .......
2016-12-06 14:17:02.106 INFO 18229 --- [pool-1-thread-5] .....
2016-12-06 14:17:02.243 DEBUG 18229 --- [ool-1-thread-19] .....
2016-12-06 14:17:02.243 INFO 18229 --- [ool-1-thread-19] ....
2016-12-06 14:17:02.587 DEBUG 18229 --- [ool-1-thread-16] .....
2016-12-06 14:17:02.587 DEBUG 18229 --- [ool-1-thread-16] ....
2016-12-06 14:17:02.587 DEBUG 18229 --- [ool-1-thread-16] .....
2016-12-06 14:17:02.587 DEBUG 18229 --- [ool-1-thread-16] .....
2016-12-06 14:17:02.588 DEBUG 18229 --- [ool-1-thread-16] .....
2016-12-06 14:17:02.588 DEBUG 18229 --- [ool-1-thread-16] ......
2016-12-06 14:17:02.588 DEBUG 18229 --- [ool-1-thread-16] .....
2016-12-06 14:17:02.588 DEBUG 18229 --- [ool-1-thread-16] ....
2016-12-06 14:17:02.588 DEBUG 18229 --- [ool-1-thread-16] ......
2016-12-06 14:17:02.588 DEBUG 18229 --- [ool-1-thread-16] ...
The logs of a thread appears sequentially all in a row, it doesn’t make sense to me. Any idea ?
What is the configuration of
pool
? Post the code. Also it is interesting to post more information about theHTMLParser
, including the lines that log the result below and anything that might be synchronizing the code. Just looking at the lines of code you posted doesn’t tell you much about the problem.– Anthony Accioly