Java Concurrency ReentrantLock
Why ReentrantLock is more flexible than synchronize block, and an example of how to use it.
Join the DZone community and get the full member experience.
Join For FreeIn this article, we will discuss Java ReentrantLock. ReentrantLock is somewhat similar to synchronize block, but provides much more flexibility. I encourage all my readers to use ReentrantLock as it is extrinsic in nature and developers have much more control over it, unlike synchronize.
Benefits of Using ReentrantLock Over Synchronize.
Reentrant Lock has some important methods. Please see the picture below:
ReentrantLock Working: Once a thread is locked, the lock hold count is increaseed by one. When that same thread is released, its count is decreased by 1.
Example
Usage of ReentrantLock to Transfer money from one account to another.
package com.example.concurrency.reentrant;
import java.util.concurrent.locks.ReentrantLock;
public class Account {
private ReentrantLock implicitLock= new ReentrantLock();
private String name;
private Integer balance=10000;
public ReentrantLock getImplicitLock() {
return implicitLock;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getBalance() {
return balance;
}
public void setBalance(Integer blance) {
this.balance = blance;
}
public boolean debit(Integer amount)
{
if(amount > balance)
{
System.out.println(Thread.currentThread().getName() + " :: " +name + " says ::"+ amount + " grater than current balance" );
return false;
}
balance = balance -amount;
System.out.println(Thread.currentThread().getName() + " :: " + name + " says ::"+ amount + " Debited Success Fully" );
return true;
}
public void credit(Integer amount)
{
balance = balance +amount;
System.out.println(Thread.currentThread().getName() + " :: " + name + " says ::"+ amount + " Credited Success Fully" );
}
}
package com.example.concurrency.reentrant;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
public class AcountTransfer {
private ReentrantLock lock= new ReentrantLock();
public void transfer(Account from,Account to,Integer amount)
{
boolean transfer = false;
try
{
if(lock.tryLock())
{
System.out.println(Thread.currentThread().getName() + " says accuire lock");
boolean flag = from.debit(amount);
if(flag)
{
to.credit(amount);
}
System.out.println(Thread.currentThread().getName()+ " :: " + from.getName() + " says :: now balance is " + from.getBalance());
System.out.println(Thread.currentThread().getName()+ " :: " + to.getName() + " says :: now balance is " + to.getBalance());
transfer = true;
}
else
{
System.out.println(Thread.currentThread().getName() + " says fail to accuire both lock Try again");
transfer(from,to,amount);//try again
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
if(transfer)
{
lock.unlock();
}
}
}
public static void main(String[] args) {
ExecutorService service = Executors.newFixedThreadPool(3);
Account from = new Account();
from.setBalance(20000);
from.setName("Shamik Mitra");
Account to = new Account();
to.setName("Samir Mitra");
AcountTransfer transfer = new AcountTransfer();
Runnable a = new Runnable(){
public void run()
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
transfer.transfer(from, to, 200);
System.out.println(Thread.currentThread().getName() +" says :: Transfer successfull");
}
};
Runnable b = new Runnable(){
public void run()
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
transfer.transfer(to, from, 1000);
System.out.println(Thread.currentThread().getName() +" says :: Transfer successfull");
}
};
for(int i=0;i<4;i++)
{
service.submit(a);
service.submit(b);
}
}
}
Output
pool-1-thread-1 says accuire lock
pool-1-thread-2 says fail to accuire both lock Try again
pool-1-thread-1 :: Shamik Mitra says ::200 Debited Success Fully
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-1 :: Samir Mitra says ::200 Credited Success Fully
pool-1-thread-2 says fail to accuire both lock Try again
pool-1-thread-1 :: Shamik Mitra says :: now balance is 19800
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-1 :: Samir Mitra says :: now balance is 10200
pool-1-thread-2 says fail to accuire both lock Try again
pool-1-thread-1 says :: Transfer successfull
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-2 says accuire lock
pool-1-thread-2 :: Samir Mitra says ::1000 Debited Success Fully
pool-1-thread-2 :: Shamik Mitra says ::1000 Credited Success Fully
pool-1-thread-2 :: Samir Mitra says :: now balance is 9200
pool-1-thread-2 :: Shamik Mitra says :: now balance is 20800
pool-1-thread-2 says :: Transfer successfull
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says accuire lock
pool-1-thread-3 :: Shamik Mitra says ::200 Debited Success Fully
pool-1-thread-3 :: Samir Mitra says ::200 Credited Success Fully
pool-1-thread-3 :: Shamik Mitra says :: now balance is 20600
pool-1-thread-3 :: Samir Mitra says :: now balance is 9400
pool-1-thread-3 says :: Transfer successfull
pool-1-thread-2 says accuire lock
pool-1-thread-2 :: Shamik Mitra says ::200 Debited Success Fully
pool-1-thread-2 :: Samir Mitra says ::200 Credited Success Fully
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-2 :: Shamik Mitra says :: now balance is 20400
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-2 :: Samir Mitra says :: now balance is 9600
pool-1-thread-2 says :: Transfer successfull
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-3 says accuire lock
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-3 :: Samir Mitra says ::1000 Debited Success Fully
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-3 :: Shamik Mitra says ::1000 Credited Success Fully
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-3 :: Samir Mitra says :: now balance is 8600
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-3 :: Shamik Mitra says :: now balance is 21400
pool-1-thread-1 says fail to accuire both lock Try again
pool-1-thread-3 says :: Transfer successfull
pool-1-thread-1 says accuire lock
pool-1-thread-1 :: Samir Mitra says ::1000 Debited Success Fully
pool-1-thread-1 :: Shamik Mitra says ::1000 Credited Success Fully
pool-1-thread-1 :: Samir Mitra says :: now balance is 7600
pool-1-thread-1 :: Shamik Mitra says :: now balance is 22400
pool-1-thread-1 says :: Transfer successfull
pool-1-thread-2 says accuire lock
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-2 :: Shamik Mitra says ::200 Debited Success Fully
pool-1-thread-2 :: Samir Mitra says ::200 Credited Success Fully
pool-1-thread-2 :: Shamik Mitra says :: now balance is 22200
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-2 :: Samir Mitra says :: now balance is 7800
pool-1-thread-2 says :: Transfer successfull
pool-1-thread-3 says fail to accuire both lock Try again
pool-1-thread-3 says accuire lock
pool-1-thread-3 :: Samir Mitra says ::1000 Debited Success Fully
pool-1-thread-3 :: Shamik Mitra says ::1000 Credited Success Fully
pool-1-thread-3 :: Samir Mitra says :: now balance is 6800
pool-1-thread-3 :: Shamik Mitra says :: now balance is 23200
pool-1-thread-3 says :: Transfer successfull
-
Published at DZone with permission of Shamik Mitra, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments