I need to perform some operations in a different thread in the benchmark, so that they do not create them every time, I want to have a trade pool and perform these operations in it.

Is a quick java ExecutorService enough or is it worth writing your own?

  • one
    ExecutorService this interface if that. Therefore, love will have to write the implementation .. - Drakonoved
  • What is fast thread pool? Try to answer this question in order to understand that the original question simply does not make sense. - etki
  • @etki fast trade pool is a trade pool that performs what I need: I want to call submit from it, and it will take a free stream and run my runnable in it. Is it not obvious to you? - voipp
  • 2
    @voipp you now describe any thread pool - etki
  • @etki I will explain: I need what he would do only that and no more, no more functionality. - voipp

1 answer 1

Judging by what happens inside the ThreadPoolExecutor code, it does not suit you. Because a stream for a new task is created inside it, this can be avoided by creating such a stream using an empty task in advance, but still a lot of logic remains. I think something of my AtomicReference that will be in a cycle to expect the appearance of something in the AtomicReference or ConcurrentQueue be faster.

This is on the one hand. On the other hand, do not forget that in any case there is such a thing as the operating system and the time to switch context when changing the flow. You still will not be able to avoid some delays. (if you have ever written tests say on bc, then there always results differed by 10-20, sometimes even by 100ms - that's your system)

That is, you already have restrictions on the duration of the test, so that you can somehow reduce the work of the system to "within the margin of error."

Third Java machine. It constantly optimizes the code, it is very difficult to be guided by the numbers obtained simply by self-writing tests with System.currentTimeMillis. This is already a topic for a separate issue, there are certain benchmarks, there are lists of rules, it is difficult to suggest something concrete, I didn’t need to get exact figures.

Fourth, what is this benchmark with separate streams? Of course, you can have "everything is under control" there and you understand what you are doing, but it sounds strange. At least in conjunction with the troubles about the speed of thread pool.

In general, as a conclusion - the thread pool is not the biggest problem that you have. Use a regular ThreadPoolExecutor, if you suddenly find that it affects something there, well, write your implementation. This is in fact a matter of 10 minutes.

  • Switching the context of threads is something that I should take into account in the benchmark, this is normal. Just do not forget about warming up the benchmark - voipp