Locksupport for Java concurrency_ Power node Java college sorting

Locksupport introduction

Locksupport is the basic thread blocking primitive used to create locks and other synchronization classes. Park() and unpark() in locksupport are used to block threads and unblock threads respectively, and park() and unpark() will not encounter the problem of "deadlock caused by thread.suspend and thread.resume". Because Park () and unpark () have licenses; The competition between the thread calling Park () and another thread trying to unpark () it will remain active.

Locksupport function list

Locksupport example

Compare "example 1" and "example 2" below to understand the usage of locksupport more clearly.

Example 1

Example 2

Operation results:

main start ta main block ta wakup others main continue

Note: the difference between park and wait. Before wait blocks the thread, you must obtain the synchronization lock through synchronized.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>