Untitled
unknown
plain_text
8 months ago
833 B
0
Indexable
Never
public class Main { public static void main(String[] args) { Thread1 thread1 = new Thread1(); Thread2 thread2 = new Thread2(); thread1.start(); thread2.start(); } static class FooTest { static volatile int x = 1; public synchronized static void foo1() { while (true) { x = -x; } } public static void foo2() { System.out.println("x = " + x); } } static class Thread1 extends Thread { @Override public void run() { FooTest.foo1(); } } static class Thread2 extends Thread { @Override public void run() { while (true) { FooTest.foo2(); } } } }