In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the main packages of the thread concurrency library of Java". In the operation of actual cases, many people will encounter such a dilemma, 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!
(1) java.util.concurrent package
Java.util.concurrent contains many thread-safe, well-tested, high-performance concurrent building blocks. To put it bluntly, the purpose of creating java.util.concurrent is to implement the concurrent operations performed by the Collection framework on data structures. By providing a set of reliable, high-performance concurrent building blocks, developers can improve the thread safety, scalability, performance, readability, and reliability of concurrent classes, as we will describe later. If some class names look similar, it may be because many concepts in java.util.concurrent are derived from Doug Lea's util.concurrent library.
(2) java.util.concurrent.atomic package
Check out the introduction below the atomic package documentation page, which can operate on multithreaded basic data, basic data in arrays and basic data in objects (AtomicInteger, AtomicIntegerArray, AtomicIntegerFieldUpDater... )
Quickly understand the meaning of atomic packages in the following two ways:
Boolean compareAndSet (expectedValue, updateValue) of the AtomicInteger class
Int addAndGet (int I, int delta) of the AtomicIntegerArray class
To explain the role of the volatile type, by the way, you need to look at the java language specification. A variable modified by volatile. Each time a thread uses a variable, it reads the most modified value of the variable. (with visibility) volatile has no atomicity.
(3) java.util.concurrent.lock package
Provides a framework interface and class for locks and wait conditions, which is different from built-in synchronization and monitors. The framework allows for more flexible use of locks and conditions. There are three APIs under this package, which are briefly introduced below:
Lock interface: supports lock rules with different semantics (reentrant, fair, etc.) that can be used in the context of non-blocking structures, including hand- over-hand and lock rearrangement algorithms. The main implementation is ReentrantLock.
ReadWriteLock interface: similarly defines locks that readers can share and writers own. This package provides only one implementation, ReentrantReadWriteLock, because it applies to most standard usage contexts. But programmers can create their own implementations that apply to non-standard requirements.
Condition interface: describes the condition variables that may be associated with the lock. These variables are similar in usage to implicit monitors accessed by Object.wait, but provide more powerful functionality. In particular, a single Lock may be associated with multiple Condition objects. To avoid compatibility issues, the name of the Condition method is different from that in the corresponding version of Object.
This is the end of the content of "what are the main packages of the thread concurrency library of Java". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.