0

This question is about thread pools in Java and can be very generic.

The Executors class provide with two classes of thread pools which can be configurable through ThreadPoolExecutor class: ScheduledThreadPool and FixedThreadPool.

ThreadPoolExecutor allows you to set the number of core threads and the max size of the thread pool.

So my question is how to choose these values -maybe related to number of processors or threads expected to be submited- in order to get maximum performance and/or fastest execution time.

Thank you in advance,

Enrique

  • you might get some inspiration here : http://stackoverflow.com/questions/130506/how-many-threads-should-i-use-in-my-java-program – Tom Mac Jan 15 '15 at 11:33
  • 1
    May be this will be useful for you: http://docs.oracle.com/javase/tutorial/essential/concurrency/further.html – DmitryKanunnikoff Jan 15 '15 at 11:35

1 Answers1

1

The is a no way to just get the optimal number of thread, it depends a lot of what you intend to do with the treads. If you plan to do some heavy calculation with the treads you want them to match the number of processor core the computer have. If you plan to use it for network request, use as many threads as you got request. Are you reading or writing from disks. Use one thread for each file that is on separate disk.

Other then that just experiment and see what gives you the best result.

Icy Creature
  • 1,875
  • 2
  • 28
  • 53