变量只能设置一次方法 AtomicBoolean started = new AtomicBoolean(false) if(started.compareAndSet(false, true)){ //todo something } 采用原子操作