系列文章目录
简述
关键字 volatile 的主要作用是使变量在多个线程间可见
解决死循环
示例
class ThreadTest7 implements Runnable{
private boolean isRunnning = true;
@Override
public void run() {
System.out.println("Thread begin: "+Thread.currentThread().getName());
while (isRunnning == true){
}
System.out.println("Thread end: "+Thread.currentThread().getName());
}
public boolean isRunnning() {
return<