How to lock with ReentrantLock?

前端 未结 3 1757
名媛妹妹
名媛妹妹 2021-01-29 09:49

I would expect the following test to only print \"has been locked\" once. BUT it consequently prints the line.

public class LocKTest {
    @Test
    public void          


        
3条回答
  •  情书的邮戳
    2021-01-29 10:40

    The name is ReentrantLock, meaning you can re-enter if you already own the lock.

    If you wish to have the thread block, you could use for example a Semaphore with 1 (or more) permits.

提交回复
热议问题