Explain in detail the thread support of executorservice, callable and future in JDK

Explain in detail the thread support of executorservice, callable and future in JDK

1. Code background:

If there are thread1, thread2, thread3 and thread4 threads to count the sizes of C, D, e and f disks respectively, and all threads are counted and handed over to thread5 thread for summary, how should it be realized?

2. Code:

The code for counting the size of the "plate", which implements the callable interface in the JDK,

The code for statistical summary also implements the callable interface in the JDK,

Client: use executors. In JDK The newfixedthreadpool method creates executorservice. The submit method of executorservice receives the implementation of the callable interface. The JDK will be processed as a thread, and the future will be used to receive the return value of the submit method. When the future calls the get method, if the thread has not finished executing, the program is blocked here until the thread has finished executing.

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>