how many threads to run in java?

前端 未结 9 598
时光取名叫无心
时光取名叫无心 2021-02-03 16:05

I had this brilliant idea to speed up the time needed for generating 36 files: use 36 threads!! Unfortunately if I start one connection (one j2ssh connection object

9条回答
  •  走了就别回头了
    2021-02-03 16:49

    One way to tune the numebr of threads to the size of the machine is to use

    int processors = Runtime.getRuntime().availableProcessors();
    int threads = processors * N; // N could 1, 2 or more depending on what you are doing.
    ExecutorService es = Executors.newFixedThreadPool(threads);
    

提交回复
热议问题