Introduction to Java Development 2.0:kilim

Source: Internet
Author: User

A role framework for implementing Java concurrency

Introduction: Concurrent programming is the core concept of Java™ Development 2.0, but it may not be thread-based concurrency. Andrew Glover explains why roles are better than threads in concurrent programming in multi-core systems. He then introduced kilim--, a role-based messaging framework combining concurrent programming and distributed programming.

For software developers, debugging an indeterminate flaw in a multithreaded application is the most painful task. So, like most people, I love using functional languages such as Erlang and Scala to do concurrent programming.

Both Scala and Erlang adopt a role model for concurrent programming, with no threading concept. The innovation around the role model is not limited to the language itself, but the role model can be used by Kilim and other java-based role frameworks.

Kilim's use of the role model is straightforward, and you'll see later that the library makes building concurrent applications incredibly simple.

Multi-nuclear challenge

In 2005, Herb Sutter wrote a still quite famous article "The Free Lunch is over:a fundamental Turn toward concurrency in Software". In this article, he rejects the idea that Moore's law will continue to promote the increasing CPU clock rate.

Sutter predicted the end of the "free Lunch", and it was no longer possible to lift the performance of the software application with the increasingly fast chip. Instead, he argues that a significant increase in application performance will require the use of multi-core chip architectures.

It turns out that he is right. Chip makers have reached a rigid limit, with chip rates already stable at 3.5 GHz for years. Moore's law continues to be met in the multi-core field as manufacturers increase the number of cores on their chips more and more quickly.

Sutter also mentions that concurrent programming will enable developers to leverage multi-core architectures. But, he adds, "We desperately need a more advanced concurrency programming model than the programming models available in various languages today." ”

The basic programming model for languages such as Java is thread based. Although multithreaded applications are not difficult to write, they still face many challenges to write correctly. One of the difficulties with concurrent programming is the use of threads to consider concurrency. There are many concurrent models, and a particularly interesting model that has been recognized by the Java community is the role model.

Role model

The role model is a different mode of concurrent process modeling. Unlike threads that interact with locks through shared memory, the role model leverages the "role" concept and uses mailboxes to deliver asynchronous messages. Here, mailboxes are similar to real-life mailboxes, and messages can be stored and retrieved by other roles for processing. Mailboxes effectively separate processes from each other, rather than sharing variables in memory.

Roles act as separate and completely different entities and do not share memory for communication. In fact, a role can only communicate through a mailbox. There are no locks and synchronized blocks in the role model, so there are no problems caused by them, such as deadlocks, serious loss updates. Also, roles can work concurrently, rather than in a sequential fashion. Therefore, roles are more secure (no locks and synchronizations are required), and the role model itself can handle coordination issues. In essence, the role model makes concurrent programming simpler.

The role model is not a new concept, it has existed for a long time. The concurrency model for some languages, such as Erlang and Scala, is role-based rather than thread based. In fact, Erlang's success in the enterprise environment (Erlang was created by Ericsson and has a long history in the telecommunications field) has undoubtedly made the role model more popular, more exposed, and a viable option for other languages. Erlang is an excellent example of a more secure concurrent programming approach to role models.

Unfortunately, the role model is not implanted into the Java platform, but we can use it in a variety of ways. The openness of the JVM to alternative languages means that you can leverage roles through the Java platform language, such as Scala or Groovy. Alternatively, you can try a Java-based library that supports role models, such as Kilim.

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.