Increase thread start performance in java

Is there a way to increase the performance of the Thread.start method. since I know that Thread.start will call the tread run method in a separate thread, but I have found that it needs more time than just calling the method in the calling context.

+4
source share
4 answers

Running threads is definitely associated with overhead. You might want to consider a thread pool.

http://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html

+7
source

Thread.start is native. This is much more than a run call - it uses operating system calls to create a stack of threads and many other things. Consider using Thread Pool .

+2
source

Initial threads, context switching, and thread killing require expensive processor cycles. Therefore, it is best to use Streaming that suits your requirements.

Various options are available:

  • Cached Thread Pool - Caches some threads to improve performance

  • One row pool performer is the only thread performer

  • Pool Pool Fixed - Fixed Size Contractor

Switching can be reduced by creating n threads based on your hardware configuration and other parameters.

The advantage of performers over Thread.start() :

  • Use existing threads so that threads are not created every time a task is submitted.
  • Flow control is performed by performers
+2
source

Creating a theme always takes time. Traditional approach

 new Thread(runnableObj).start(); 

creates a new Thread every time we call the start () method.

Use Executors if you don't want to spend extra time creating threads while running business logic. When you start the application, you can configure and create thread pools .

Here is a good short tutorial for Performers

+2
source

Source: https://habr.com/ru/post/1486657/


All Articles