class LockingThread1 implements Runnable{
private volatile int number=0;
LockingThread2 a=new LockingThread2();
@Override
public void run() {
a.Add(7);
// Add(5);
}
synchronized void Add(int numberValue){
number=number+numberValue;
System.out.println(number);
}
}
class LockingThread2 {
// private volatile int number=0;
private int number=0;
// synchronized void Add(int numberValue){
// number=number+numberValue;
// System.out.println(number);
// }
void Add(int numberValue){
number=number+numberValue;
System.out.println(number);
}
}
public class LockingThread{
public static void main (String [] args) throws Exception
{
LockingThread1 thread1=new LockingThread1();
// LockingThread1 thread2=new LockingThread1();
// LockingThread1 thread3=new LockingThread1();
Thread no1=new Thread(thread1);
Thread no2=new Thread(thread1);
Thread no3=new Thread(thread1);
// no1.start();
// no2.start();
// no3.start();
//
no1.start();
no2.start();
no3.start();
}
}
No comments:
Post a Comment