Threads with no wait in Java

Bilal :

I am bit new in Java Threading and concurrency. I have read about synchronized and lock blocks. They let other Threads to wait until first Thread complete its work.

I just want to know a way that if THREAD A is performing its execution, then THREAD B should not wait and skip the execution of that shared code block.

Andrew Tobilko :

Thread B could try to acquire the lock by Lock.tryLock. If it's not available, Thread B may skip "the execution of that shared code block" immediately after the check.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=139470&siteId=1