package Test_MoreThread;
public class Thread_2 {
JManager j = new JManager();
public static void main(String args[]){
new Thread_2().call();
}
void call() {
for (int i = 0; i < 2; i++) {
new Thread(new Runnable() {
@Override
public void run() {
j.inc();
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
j.dec();
}
}).start();
}
}
}
class JManager{
private int j = 0;
public synchronized void inc(){
j++;
System.out.println(Thread.currentThread().getName()+"-inc:"+j);
}
public synchronized void dec(){
j--;
System.out.println(Thread.currentThread().getName()+"-dec:"+j);
}
}