java - Callable code won't use more than one CPU with ThreadPoolExecutor -
i have quad core processor , threadpoolexecutor set 4 core threads, when submit callables (hundred or so) threadpoolexecutor, java never uses more 25% cpu. why not use of them?
code in question:
static class sum implements callable{ private double bigarray[]; public sum(double [] bigarray){ this.bigarray = bigarray; } @override public double call(){ double sum = 0; (int = 0; < bigarray.length; i++){ sum += bigarray[i]; } return sum; } }
in general, there no interface in java control cores , processors affinity code (and threads) scheduled os finds right. might not it. said running multiple threads on multiple cpu cores?
in general not job jvm; os allocates core thread, jvm program. if you're running on ms windows machine can try set 'affinity' jvm, i.e. tell scheduler (task manager) cpus (cores) jvm allowed use.
but not think way go.
see answer stack overflow question how java makes use of multiple cores?.
Comments
Post a Comment