@@ -0,0 +1,807 @@
+package sample.jcu.lock;%0A%0Aimport java.util.concurrent.atomic.AtomicReference;%0A%0A/**%0A * @author soyona%0A * @Package sample.jcu.lock%0A * @Desc: %E8%87%AA%E6%97%8B%E9%94%81%E5%AE%9E%E7%8E%B0%EF%BC%8C%E4%BB%A3%E7%A0%81%E6%9D%A5%E8%87%AA%EF%BC%9Ahttp://ifeve.com/java_lock_see1/%0A * @date 2018/7/12 17:55%0A */%0Apublic class SpinLock %7B%0A    private AtomicReference%3CThread%3E sign =new AtomicReference%3C%3E();%0A%0A    /**%0A     *%0A     * unsafe.compareAndSwapObject(this, valueOffset, expect, update)%0A     *%0A     * AtomicReference %E5%AE%9E%E4%BE%8B%E5%AF%B9%E8%B1%A1%E7%9A%84 %E5%81%8F%E7%A7%BB%E9%87%8F %E6%9D%A5%E8%8E%B7%E5%8F%96 %E7%BA%BF%E7%A8%8B%E5%AF%B9%E8%B1%A1%0A     *%0A     */%0A    public void lock()%7B%0A        Thread current = Thread.currentThread();%0A        //CAS%E4%B8%8D%E6%88%90%E5%8A%9F %E7%BB%A7%E7%BB%AD%E5%BE%AA%E7%8E%AF%EF%BC%8CCAS%E6%88%90%E5%8A%9F %E7%BB%93%E6%9D%9F%E5%BE%AA%E7%8E%AF%0A        while(!sign .compareAndSet(null, current))%7B%0A        %7D%0A    %7D%0A%0A    public void unlock()%7B%0A        Thread current = Thread.currentThread();%0A        //CAS%E4%B8%8D%E6%88%90%E5%8A%9F %E7%BB%A7%E7%BB%AD%E5%BE%AA%E7%8E%AF%EF%BC%8CCAS%E6%88%90%E5%8A%9F %E7%BB%93%E6%9D%9F%E5%BE%AA%E7%8E%AF%0A        while(!sign .compareAndSet(current, null))%7B%0A        %7D%0A    %7D%0A%0A%7D%0A

add SpinLock From http://ifeve.com/java_lock_see1/