Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis on the birth of J.U.C concurrent package in Java

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "Analysis of the birth of J.U.C concurrency packages in Java". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

About JCP and JSR

JCP, short for Java Community Process, is a process for developing and revising Java technical specifications. At the same time, we mention that JCP generally refers to the organization that maintains and manages this set of processes. This organization is mainly composed of Java developers and authorized non-profit organizations, who are in charge of the development direction of Java. JCP was put forward by Sun Company on December 8, 1998, which aims to promote the development of Java through the power of java community. So far, it has developed from version 1.0 to the latest version 2.11, which was issued on July 21, 2019. There are four main stages in the JCP process, namely, startup, release of draft, final version, and maintenance. The new function of a Java will appear in the next version of JDK from the start-up stage to the complete set of process smoothly.

JSR is the abbreviation of Java Specification Requests and the specification for proposing draft in the start-up phase of the service JCP. Anyone who registers as a member of JCP can submit JSR to JCP. For example, you think that the operation method of String in JDK is not as practical as that in guava. You suggest a method in JSR to enhance String. As long as it can pass the review of JCP, you can see it in the next version of JDK. We are familiar with proposals such as Java cache api's JSR-107, Bean property verification JSR-303, and, of course, the Java concurrent package JSR-166 that this article will talk about.

JCP official website: https://jcp.org

Doug Lea and his JSR-166

Doug Lea, Chinese name is Doug Leigh. Is a university teacher in the United States, the great divine figure, J.U.C is from his hand. Before JDK1.5, we could only use synchronized to control the program's concurrent access to synchronous code. At that time, the performance of synchronized was not optimized, the performance was not good, and the control thread could only use Object's wait and notify methods. At this time, Doug Lea submitted JSR-166 's proposal to JCP. Before submitting JSR-166, Doug Lea has been using code similar to J.U.C package for more than three years. This code is the prototype of J.U.C. Here is a brief look at these historical code. At the same time, it can also cause us to think, if not in JDK, then make your own!

Prototype of Lock interface public class Mutex implements Sync {/ * * The lock status * * / protected boolean inuse_ = false; @ Override public void acquire () throws InterruptedException {if (Thread.interrupted ()) {throw new InterruptedException ();} synchronized (this) {try {/ / if inuse_ is true, wait thread while (inuse_) {wait ();} inuse_ = true } catch (InterruptedException ex) {notify (); throw ex;} / * release the lock and notify the thread to continue executing * / @ Override public synchronized void release () {inuse_ = false; notify ();} @ Override public boolean attempt (long msecs) throws InterruptedException {if (Thread.interrupted ()) {throw new InterruptedException () } synchronized (this) {if (! inuse_) {inuse_ = true; return true;} else if (msecs)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report