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

What is AbstractQueuedSynchronizer?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the knowledge of "what is AbstractQueuedSynchronizer". In the operation of actual cases, many people will encounter such a dilemma. Then 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!

AbstractQueuedSynchronizer Abstract Class

Implement the following methods alone in the subclass

* {@ link # tryAcquire} * {@ link # tryRelease} * {@ link # tryAcquireShared} * {@ link # tryReleaseShared} * {@ link # isHeldExclusively}

State status modification uses the following methods

{@ link # getState}, {@ link* # setState} {@ link # compareAndSetState}:

Node {

/ / indicates the node status, CANCELLED. A value of 1 indicates that the current thread is canceled. The SIGNAL value is-1.

/ / indicates that the successor node of the current node contains threads that need to be run, that is, unpark

/ / the condition value is-2, which means that the current node is waiting for condition, that is, condition queue.

/ / propagate. The value is-3, which means that subsequent acquireShared in the current scene can be executed.

/ / the value is 0, indicating that the current node is in the sync queue, waiting to acquire the lock

Int waitStatus

/ / precursor node. If you cancel the current node, you need to complete the connection.

Node prev

/ / successor node

Node next

/ / Store the successor nodes in the condition queue

Node nextWaiter

/ / the current thread queued

Thread thread

}

/ / get an exclusive lock

While (acquire Lock) {

If (obtained) {

Exit the while loop

} else {

If (the current thread is not queued) {

Then join the queue.

}

Block the current thread

}

}

}

}

/ / release an exclusive lock

If (released successfully) {

Delete header node

Activate the successor node of the original header node

}

That's all for "what AbstractQueuedSynchronizer is". 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.

Share To

Internet Technology

Wechat

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

12
Report