Java Polygon Questions-concurrent containers and frames

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.