Skip to content

Instantly share code, notes, and snippets.

@j5ik2o
Created November 19, 2011 09:45
Show Gist options
  • Save j5ik2o/1378662 to your computer and use it in GitHub Desktop.
Save j5ik2o/1378662 to your computer and use it in GitHub Desktop.
可視性のテスト
package test;
import java.util.concurrent.TimeUnit;
public class StopThreadTest {
private static boolean stopRequested;
public static void main(String[] args) {
Thread t = new Thread(new Runnable() {
public void run() {
int i = 0;
while (stopRequested == false) {
i++;
}
}
});
t.start();
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
stopRequested = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment