SpringApplicationBuilder.run方法

这里有CAS了,为什么里面还要用synchronized?

      public ConfigurableApplicationContext run(String... args) {
        if (this.running.get()) {
            // If already created we just return the existing context
            return this.context;
        }
        configureAsChildIfNecessary(args);
        if (this.running.compareAndSet(false, true)) {
            synchronized (this.running) {
                // If not already running copy the sources over and then run.
                this.context = build().run(args);
            }
        }
        return this.context;
    }

img

很多安全的函数或者类,其实他的底层就是用了synchronized 处理,或者lock处理。

防止ABA问题