public class TreadSafeTest {
// Vector<Integer> data = new Vector<Integer>();
//
List<Integer> data = new ArrayList<Integer>(1);
{
data.add(99);
}
public static void main(String[] args) throws Exception {
new TreadSafeTest().test();
}
public void test() throws Exception {
new Thread() {
int count = 10000;
public void run() {
try {
while (count < 10009) {
count++;
System.out.println("1:" + data.get(0));
data.set(0, count);
System.out.println("1:" + data.get(0));
}
} catch (Exception e) {
System.out.println(e);
}
};
}.start();
new Thread() {
int count = 20000;
public void run() {
try {
while (count < 20009) {
count++;
System.out.println("2:" + data.get(0));
data.set(0, count);
System.out.println("2:" + data.get(0));
}
} catch (Exception e) {
}
};
}.start();
}
}