public static class Prm
{
public int ATM_total = 200;
}
public class ATM extends Thread
{
public static void main(String args[])
{
AThread aThread = new AThread();
aThread.start();
BThread bThread = new BThread();
bThread.start();
}
}
public class AThread extends Thread
{
public void run()
{
int amt = Prm.ATM_total;
try
{
this.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
amt += 100;
Prm.ATM_total = amt;
try
{
this.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
public class BThread extends Thread
{
public void run()
{
int amt = Prm.ATM_total;
try
{
this.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
if(amt > 50)
{
amt -= 50;
}
else
{
throw new Exception();
}
Prm.ATM_total = amt;
try
{
this.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}