1. How do I make a program run concurrently and eventually summarize the results?
A: Using Cyclicbarrier and Countdownlatch, you can use Cyclicbarrier to perform a summary of the results at multiple gates, Countdownlatch report the results to the bus after each thread has finished executing.
2. How to properly configure the Java thread pool? such as CPU-intensive tasks, how large should the basic thread pool be configured? IO-intensive tasks, how large should the basic thread pool be configured? Is it good to use bounded queues or unbounded queues? What blocking queues can be used to get the best throughput when there are very many tasks?
A: 1) when configuring the thread pool, CPU-intensive tasks can be configured with fewer threads, presumably equivalent to the number of CPU cores of the machine, allowing each thread to perform tasks
2) IO-intensive, most of the threads are blocked, it is necessary to configure the number of threads, 2*cpu the number of cores
3) bounded queues and unbounded queues are configured to differentiate between business scenarios and, in general, to configure bounded queues to use unbounded queues in the case of some potentially explosive growth.
4) with a very long task, the use of non-blocking queues to replace locks with CAS operations can achieve good throughput.
3. How do I use a blocking queue to implement a producer and consumer model?
4. Which concurrent container should be used for multi-read and less-written scenes, and why use it? For example, you do a search engine, search engine every time before you need to determine whether search keywords in the blacklist, the blacklist updated every day.
A: 1) copyonwritearraylist This container is suitable for more reading and less writing ...
2) Read and write are not on the same object. When writing, it will copy the array in large area, so the performance of writing is poor, and the read reference will be changed to write object after writing.
Java Polygon Questions-concurrent containers and frames