Concurrent Program Design (1)

Source: Internet
Author: User
Herb Suter's Point of View

In a recent article by Herb Suter, the author said: "In 1990s, we talked to people everywhere about what objects are and what virtual functions are. Now we talk to people everywhere about what active objects are, what is Future, "he also said. It is now time for concurrency and parallelism for structured programming and object-oriented programming.

I remember that last year, Herb Sutter wrote an article to indicate the arrival of the concurrency era, mainly because the CPU clock speed will no longer grow as before, but will usher in the multi-core era. The program will improve the running efficiency by concurrency.

JDK 1.5 Concurrent package

In traditional multi-threaded programs, there are often:
Create thread
Wait \ Policy
Re-invent the wheel, such as BlockingQueue, Lock, Semaphore and other basic tools.

Improper abstraction can lead to unbearable complexity, many code errors, frequent deadlocks, lost loss y, and other problems, which can easily lead to low performance. I have also had this experience, and the lessons of failure are unforgettable.

The JDK 1.5 util. concurrent package provides a series of tool classes. The use of some of these classes represents the transformation of some concepts. A better abstraction and elegant design pattern will make the multi-threaded program have a good structure.

Enable
A program built with Excector, ScheduleExecutorService, Future, BlockingQueue, and other classes will make the multi-thread Program
It has a clear structure. The difference seems like the previous transition from "unstructured Program Design" to "Structured Program Design". Now we use design patterns such as Future, which is just as good.
.

Structured program design, using if/else, while, do... while, for, switch and other structures, the program organization is clear and easy to understand, easier to grasp, less error.
Executor, Future, Concurrent Collection, and other tool classes and modes make the Concurrent program structure clear/modeled, making it easier to master, with fewer errors and more efficient.

With the popularization of multi-core CPUs, Moore's Law gradually becomes invalid. concurrent program design will be the basic skills that programmers need to master, just as programmers need to master object-oriented skills.

There are several documents worth reading:

Javaone slides
Http://developers.sun.com/learning/javaoneonline/2005/coreplatform/TS-3423.pdf
Http://developers.sun.com/learning/javaoneonline/2005/coreplatform/TS-5807.pdf

Doug Lea's article
Http://gee.cs.oswego.edu/dl/papers/aqs.pdf

The above document can only give you an introduction. The best way is to read the source code of the JDK 1.5 utilconcurrent package. Then, in practice, change your mindset and accumulate experience.

Concurrency and Network Programming

Network
There is a central server in the network. The interaction between different machines, concurrency and Asynchronization are common actions. The server in the network requires a large number of concurrency, which is usually extreme concurrency, and the operating system provides some special
API, such as the select model, poll, and windows completion port. JDK supports nio after 1.4, mainly for large concurrency.

The C ++ framework ACE provides cross-platform threads, processes, Future, and other APIs. It also provides Reactor, Proactor, and other frameworks, making it easy to write cross-platform concurrent network servers.

One idea of the ACE framework is to use ACE and mode to eliminate complexity. This is consistent with the intent of the advanced design pattern class provided by the JDK 1.5 concurrent package.

Some modes are described in volumes 1 and 2 of C ++ network programming, such as Half Sync/Aysnc vs Leader/Follow Mode. This is some of the research results in the ACE development process. When we look for information about ACE, we will find some papers on concurrency. ACE also provides Future.

I used ACE for some simple applications, but I don't know enough about it. However, I think JDK concurrent package has gone further than ACE in the concurrent design mode.

Today, have you used Future?

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.