简体   繁体   中英

What is the role of Threads_lock in jvm and which scenarios will be used

I met a problem: In management.cpp, the jmm_GetThreadInfo method will first acquire the Threads_lock lock, assuming that there are too many threads and it is very time-consuming, which leads to a non-obvious problem: some other threads are blocked and have been waiting for this lock to be released, but I can't find where the thread will be triggered suddenly blocked on this lock.

I have some questions:

  1. the role of Threads_lock in jvm and which scenarios will be used.
  2. whether the Threads_lock will cause other threads to block.

Threads_lock is in the mutexLocker.cpp.The official explanation is

a lock on the Threads table of active Java threads
(also used by Safepoints too to block threads creation/destruction)

thranks

Threads_lock protects a list of JVM managed threads from concurrent modification. The lock is acquired when a new thread starts, when a thread exits, and at safepoints. Threads_lock does not block running threads from doing their regular work.

In JDK 8, Threads_lock was also acquired for iterating over a list of existing threads, and this indeed caused performance issues. Since JDK 10, JVM maintains thread list snapshot for lock-free read access.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM