package com.huachuan.learnjava;
public class Demo1 {
static int Ticketcount = 0;
public static Object o = new Object();
public static void main(String[] args) {
Thread t1 = new A();
Thread t2 = new B();
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(Ticketcount);
}
}
class A extends Thread {
@Override
public void run() {
synchronized (Demo1.o) {
for (int i = 0; i < 10000; i++) {
Demo1.Ticketcount++;
}
}
}
}
class B extends Thread {
public void run() {
synchronized (Demo1.o) {
for (int i = 0; i < 10000; i++) {
Demo1.Ticketcount++;
}
}
}
}
public class Demo1 {
static int Ticketcount = 0;
public static Object o = new Object();
public static void main(String[] args) {
Thread t1 = new A();
Thread t2 = new B();
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(Ticketcount);
}
}
class A extends Thread {
@Override
public void run() {
synchronized (Demo1.o) {
for (int i = 0; i < 10000; i++) {
Demo1.Ticketcount++;
}
}
}
}
class B extends Thread {
public void run() {
synchronized (Demo1.o) {
for (int i = 0; i < 10000; i++) {
Demo1.Ticketcount++;
}
}
}
}