Mixing synchronized() with ReentrantLock.lock()

前端 未结 3 1263
情话喂你
情话喂你 2021-02-05 12:37

In Java, do ReentrantLock.lock() and ReetrantLock.unlock() use the same locking mechanism as synchronized()?

My guess is \"No,\" b

3条回答
  •  感动是毒
    2021-02-05 12:50

    Why did you make the balance static in Account class? Remove static and it should work.

    Also, have a question about your thread usage. In your TestMain you create new threads and assign runnables like WithdrawRequests & DepositRequests. But again you create new threads inside the constructors of those runnables. This will cause the run method to be executed twice!

提交回复
热议问题