当前位置: 首页>后端>正文

synchronized的优化手段与java中的JUC

馃崁1.synchronized鐨勪紭鍖栨墜娈?/h2>

馃崅1.1閿佽啫鑳€/鍗囩骇

鍓嶉潰鎴戜滑璇磋繃synchronized鍏抽敭瀛楀姞鐨勯攣鏃㈡槸杞婚噺绾ч攣涔熸槸閲嶉噺绾ч攣锛屽畠鏄牴鎹疄闄呮儏鍐佃嚜閫傚簲鍔犻攣鐨勶紝杩欑鑷€傚簲鏄熀浜庨攣鑶ㄨ儉鎴栬€呰鏄攣鍗囩骇杩欐牱鐨勪紭鍖栨墜娈垫潵瀹炵幇鐨勩€?/p>

馃尭閿佸崌绾ц繃绋嬶細

  • 褰撴病鏈夌嚎绋嬪姞閿佺殑鏃跺€欙紝姝ゆ椂涓烘棤閿佺姸鎬併€?/li>
  • 褰撻涓嚎绋嬭繘琛屽姞閿佺殑鏃跺€欙紝姝ゆ椂杩涘叆鍋忓悜閿佺殑鐘舵€侊紝鍋忓悜閿佷笉鏄湡鐨勫姞閿侊紝鑰屾槸鍦ㄥ璞″ご鍋氫釜鏍囪鑰屽凡锛?/li>
  • 褰撴湁鍏朵粬绾跨▼杩涜鍔犻攣锛屽鑷翠骇鐢熶簡閿佺珵浜夋椂锛屾鏃惰繘鍏ヨ交閲忕骇閿佺姸鎬併€?/li>
  • 濡傛灉绔炰簤杩涗竴姝ュ姞鍓э紝杩涘叆閲嶉噺绾ч攣鐘舵€併€?/p>

    synchronized的优化手段与java中的JUC,第1张

鍍忎笂闈㈡牴鎹攣绔炰簤鐨勭▼搴︽潵閫愭鍗囩骇閿佺殑鎯呭喌锛屽氨鏄攣鐨勮啫鑳€鎴栬€呯О涓洪攣鐨勫崌绾с€?/p>

馃崅1.2閿佺矖鍖?/h2>

鎵€璋撻攣绮楀寲灏辨槸灏?code>synchronized鐨勫姞閿佷唬鐮佸潡鑼冨洿澧炲ぇ锛屽姞閿佺殑浠g爜鍧椾腑鐨勫唴瀹硅秺澶氾紝閿佸氨瓒婄矖锛屽惁鍒欓攣灏辫秺缁嗐€?br> 涓€鑸垜浠涓猴紝閿佽秺缁嗭紝澶氱嚎绋嬮棿鐨勫苟鍙戞€ц秺楂橈紝閿佽秺绮楋紝鍔犻攣瑙i攣鐨勫紑閿€灏变細鏇村皬銆傜紪璇戝櫒浼氬浣犲姞鐨勯攣鍋氫竴涓紭鍖栵紝濡傛灉缂栬瘧鍣ㄥ垽瀹氬姞鐨勯攣杩囩粏锛屽氨浼氳嚜鍔ㄧ矖鍖栵紝浠庤€屾彁楂樼▼搴忚繍琛屾晥鐜囥€?/p>

馃崅1.3閿佹秷闄?/h2>

鏈変簺浠g爜锛岀紪璇戝櫒璁や负娌℃湁鍔犻攣鐨勫繀瑕侊紝灏变細鑷姩鎶婁綘鍔犵殑閿佽嚜鍔ㄥ幓闄わ紝鍍忕被浼艰繖鏍风殑浼樺寲锛屽氨鏄攣娑堥櫎銆?/p>

馃崁2.java涓殑JUC

java涓殑JUC灏辨槸鏉ヨ嚜java.util.concurrent鍖呬笅鐨勪竴浜涙爣鍑嗙被鎴栬€呮帴鍙o紝閮芥槸鏈夊叧骞跺彂鎴栬€呮湁鍏冲绾跨▼鐨勪竴浜涚被鍜屾帴鍙c€?/p>

馃崅2.1Callable鎺ュ彛

鍓嶉潰鎴戜滑鍒涘缓绾跨▼鐨勬椂鍊欙紝鏈変袱绉嶆柟寮忥紝涓€鏄户鎵?code>Thred绫诲苟閲嶅啓run鏂规硶鏉ュ垱寤虹嚎绋嬶紝浜屾槸閫氳繃Runnable鎺ュ彛鏉ュ垱寤虹嚎绋嬶紝闄や笂杩颁袱绉嶆柟寮忥紝鎴戜滑杩樺彲浠ラ€氳繃Callable鎺ュ彛閰嶅悎FutureTask绫绘潵鍒涘缓绾跨▼锛屼娇鐢ㄨ鏂规硶鍒涘缓绾跨▼鑳藉鏀寔甯﹁繑鍥炲€肩殑浠诲姟锛岃€屾渶寮€濮嬬殑閭d袱绉嶆柟娉曟槸涓嶆敮鎸佸甫鍥炶繑鍥炲€肩殑銆?/p>

鍏朵腑閫氳繃瀹炵幇Callable鎺ュ彛鐨?code>call鏂规硶鏉ユ弿杩板甫鏈夎繑鍥炲€肩殑浠诲姟锛?code>FutureTask灏辨槸瀵逛簬鍏蜂綋鐨?code>Runnable鎴栬€?code>Callable浠诲姟鐨勬墽琛岀粨鏋滆繘琛屽彇娑堛€佹煡璇㈡槸鍚﹀畬鎴愩€佽幏鍙栬繑鍥炲€笺€傚繀瑕佹椂鍙互閫氳繃get鏂规硶鑾峰彇鎵ц缁撴灉锛堣繑鍥炲€硷級锛屽鏋滀换鍔¤繕娌℃湁鎵ц瀹屾瘯锛岃鏂规硶浼氶樆濉炵洿鍒颁换鍔¤繑鍥炵粨鏋溿€?/p>

鍦ㄥ垱寤虹嚎绋嬬殑鏃跺€欙紝浼犲叆鐨勫紩鐢ㄤ笉鑳芥槸Callable绫诲瀷锛岃€屽簲璇ユ槸FutrueTask绫诲瀷锛屾牴鎹?code>Thread鐨勬瀯閫犳柟娉曪紝浼犲叆鐨勪换鍔$被鍨嬮渶鏄?code>Runnable绫伙紝Callable涓?code>Runnable娌℃湁鍏崇郴锛岃€?code>FutrueTask绫诲疄鐜颁簡Runnable绫伙紝鎵€浠ュ湪姝や箣鍓嶆垜浠渶瑕佹妸瀹炵幇Callable鎺ュ彛鐨勫璞″紩鐢ㄤ紶缁?code>FutrueTask绫荤殑瀹炰緥瀵硅薄銆?[鍥剧墖涓婁紶涓?..(image-c0aaa5-1654604115299-4)]

synchronized的优化手段与java中的JUC,第2张

缁间笂锛?code>Callable鐢ㄦ潵鎻忚堪浠诲姟锛?code>FutureTask绫荤敤鏉ョ鐞?code>Callable浠诲姟鐨勬墽琛岀粨鏋溿€?/p>

synchronized的优化手段与java中的JUC,第3张

姣斿锛岀幇鍦ㄦ垜浠渶瑕佷娇鐢ㄧ嚎绋嬫潵璁$畻涓€涓€硷紝骞堕€氳繃杩斿洖鍊肩殑鏂瑰紡鑾峰彇鎵ц缁撴灉銆?/p>

馃尭鍙傝€冧唬鐮侊細

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Main {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                return 100 * (1 + 100) / 2;
            }
        };

        FutureTask<Integer> task = new FutureTask<>(callable);
        Thread thread = new Thread(task);
        thread.start();

        //鑾峰彇鎵ц缁撴灉
        System.out.println(task.get());
    }
}

馃尭杩愯缁撴灉锛?/p>

5050

Process finished with exit code 0

馃崅2.2ReentrantLock绫伙紙鍙噸鍏ラ攣锛?/h2>

ReentrantLock鍏跺疄灏辨槸鍙噸鍏ラ攣锛屼娇鐢ㄦ柟寮忔槸閫氳繃lock鏂规硶鍔犻攣锛?code>unlock鏂规硶瑙i攣锛屾敞鎰忓姞閿佸拰瑙i攣涓や釜杩囩▼鏄垎寮€鐨勶紝鑰?code>synchronized鍏抽敭瀛楀姞閿佽В閿佹槸涓€姝ュ埌浣嶇殑銆?/p>

鐢变簬鍔犻攣瑙i攣涓や釜鎿嶄綔鏄垎寮€鐨勶紝鐩告瘮浜庡姞閿佽В閿佷竴浣撳寲杩欏氨寰堝鏄撻€犳垚姝婚攣闂锛岃繖鏄洜涓轰竴鏂归潰鍔犻攣鍚庡鏄撳繕璁板幓瑙i攣锛岄€犳垚姝婚攣锛屽彟涓€鏂归潰鍔犻攣鍚庤В閿佸墠涓棿鐨勪唬鐮佷竾涓€鍑轰簡闂锛屽彲鑳戒細瀵艰嚧瑙i攣鏃犳硶姝e父鎵ц瀵艰嚧瑙i攣澶辫触锛岄€犳垚姝婚攣銆?br> 鎵€浠ヤ娇鐢?code>ReentrantLock绫绘椂锛屼竴鑸鎼厤finally浣跨敤銆?/p>

ReentrantLock lock = new ReentrantLock(); 
//dosomething
lock.lock();   
try {    
    // working    
} finally {    
    lock.unlock()    
}

馃尭ReentrantLock绫讳笌synchronized鍏抽敭瀛楀尯鍒細

  • ReentrantLock鏄竴涓猨ava鏍囧噯绫伙紝鏄娇鐢╦ava浠g爜瀹炵幇鐨勶紝synchronized鏄竴涓叧閿瓧锛屾槸鍩轰簬JVM鍐呴儴瀹炵幇鐨勶紝鏄疌/C++浠g爜銆?/li>
  • ReentrantLock闇€瑕佹墜鍔ㄨВ閿侊紝闇€璋ㄩ槻蹇樿瑙i攣锛岃€?code>synchronized鍔犻攣瑙i攣涓€浣撳寲锛屼笉闇€瑕佹墜鍔ㄨВ閿併€?/li>
  • 濡傛灉鍑虹幇閿佺珵浜夛紝ReentrantLock绔炰簤澶辫触鏃跺彲浠ラ樆濉炵瓑寰咃紝涔熷彲浠ラ€氳繃trylock鏂规硶鐩存帴杩斿洖閫€鍑猴紝鑰?code>synchronized绔炰簤澶辫触鏃跺彧鑳介樆濉炵瓑寰呫€?/li>
  • ReentrantLock鏋勯€犲疄渚嬪璞℃椂锛屽彲浠ユ寚瀹歠air鍙傛暟鏉ュ喅瀹氳閿佸璞℃槸鍏钩閿佽繕闈炲叕骞抽攣锛?code>synchronized鍔犵殑閿佹槸闈炲叕骞抽攣锛屼笉鑳芥寚瀹氫负鍏钩閿併€?/li>
  • ReentrantLock绫昏鐢熷嚭鐨勭瓑寰呮満鍒舵槸Condition绫伙紝synchronized鍏抽敭瀛楄鐢熺殑绛夊緟鏈哄埗鏄?code>wait/notify绛夊緟鏈哄埗銆?/li>

馃崅2.3Semaphore绫伙紙淇″彿閲忥級

杩欎釜姒傚康姣旇緝鎶借薄锛屾垜浠潵鎵撲釜姣旀柟锛屾湁涓仠杞﹀満锛屽仠杞﹀満闂ㄥ彛鏈変竴涓伅鐗岋紝浼氭樉绀哄仠杞︿綅杩樺墿浣欏灏戜釜锛屾瘡杩涘幓涓€杈嗚溅锛屾樉绀虹殑鍋滆溅浣嶆暟閲忓氨鍑忎竴锛屾瘡鍑哄幓涓€杈嗗嚭锛屾樉绀虹殑鍋滆溅浣嶆暟閲忓氨鍔犱竴銆?/p>

涓婇潰鏄剧ず鍋滆溅浣嶆暟閲忕殑鐏墝鍏跺疄灏辨槸淇″彿閲忥紝淇″彿閲忔槸涓€鏇村姞骞夸箟鐨勯攣锛屾弿杩颁簡鍙敤璧勬簮鐨勪釜鏁般€?br> 姣忔鐢宠涓€涓彲鐢ㄨ祫婧愶紝淇″彿閲忎腑鐨勮鏁板櫒灏卞噺涓€锛圥鎿嶄綔锛夈€?br> 姣忔閲婃斁涓€涓彲鐢ㄨ祫婧愶紝淇″彿閲忎腑鐨勮鏁板櫒灏卞姞涓€锛圴鎿嶄綔锛夈€?br> 褰撳彲鐢ㄨ祫婧愭暟閲忎负0鏃讹紝鍐嶆杩涜P鎿嶄綔锛屼細闄峰叆闃诲绛夊緟鐘舵€併€?/p>

閿佹垜浠彲浠ョ悊瑙d负鈥滀簩鍏冧俊鍙烽噺鈥濓紝鍥犱负璁℃暟鍣ㄧ殑鍙栧€间笉鏄?灏辨槸1锛屽畠鐨勫彲鐢ㄨ祫婧愬氨涓€涓€?/p>

馃尭Semaphore绫荤殑甯哥敤鏂规硶锛?/p>

搴忓彿 鏂规硶 鏂规硶绫诲瀷 浣滅敤
1 public Semaphore(int permits) 鏋勯€犳柟娉?/td> 鏋勯€犲彲鐢ㄨ祫婧愪负permits涓殑淇″彿閲忓璞?/td>
2 public Semaphore(int permits, boolean fair) 鏋勯€犳柟娉?/td> 鐩告瘮浜庢柟娉?锛岃鏋勯€犳柟娉曡繕鑳芥寚瀹氫俊鍙烽噺鏄惁鏄叕骞虫€ц川鐨?/td>
3 public void acquire() throws InterruptedException 鏅€氭柟娉?/td> 鐢宠鍙敤璧勬簮
4 public void release() 鏅€氭柟娉?/td> 閲婃斁鍙敤璧勬簮

馃尭浠g爜婕旂ず锛?/p>

import java.util.concurrent.Semaphore;
public class Main {
    public static void main(String[] args) throws InterruptedException {
        //鏋勯€犳柟娉曚腑鐨刾ermits鍙傛暟琛ㄧず鍙敤璧勬簮鐨勪釜鏁?
        Semaphore semaphore = new Semaphore(4);
        //姣忔浣跨敤涓€涓彲鐢ㄨ祫婧愶紝淇″彿閲忓氨浼氬噺灏?
        semaphore.acquire();
        System.out.println("鐢宠鎴愬姛");
        semaphore.acquire();
        System.out.println("鐢宠鎴愬姛");
        semaphore.acquire();
        System.out.println("鐢宠鎴愬姛");
        semaphore.acquire();
        System.out.println("鐢宠鎴愬姛");
        //姝ゆ椂鍙敤璧勬簮涓?锛岀嚎绋嬭繘鍏ラ樆濉烇紝闇€瑕佷娇鐢╮elease鏂规硶閲婃斁璧勬簮锛岀嚎绋嬫墠鑳界户缁墽琛?
        semaphore.release();
        System.out.println("閲婃斁鎴愬姛");
        semaphore.acquire();
        System.out.println("鐢宠鎴愬姛");
    }
}
澶嶅埗浠g爜

馃尭鎵ц缁撴灉锛?/p>

鐢宠鎴愬姛
鐢宠鎴愬姛
鐢宠鎴愬姛
鐢宠鎴愬姛
閲婃斁鎴愬姛
鐢宠鎴愬姛

Process finished with exit code 0

馃崅2.4CountDownLatch鍚屾宸ュ叿绫?/h2>

CountDownLatch鏄竴涓悓姝ュ伐鍏风被锛屽畠鍏佽涓€涓垨澶氫釜绾跨▼涓€鐩寸瓑寰咃紝鐩村埌鍏朵粬绾跨▼鎵ц瀹屽悗鍐嶆墽琛屻€?br> 鎵撲釜姣旀柟锛屽亣璁炬湁涓€鍦鸿窇姝ユ瘮璧涳紝涓€涓湁5涓繙鍔ㄥ憳鍙傝禌锛屽彧鏈夊綋鏈€鍚庝竴涓繙鍔ㄥ憳鍐茶繃缁堢偣绾挎椂锛岃鍒ゆ墠鑳藉甯冩瘮璧涚粨鏉熴€?/p>

杩欓噷鐨勮繍鍔ㄥ憳灏辩浉褰撲簬绾跨▼锛岃鍒ゅ氨鐩稿綋浜?code>CountDownLatch绫汇€?/p>

馃尭CountDownLatch鍚屾宸ュ叿绫诲父鐢ㄦ柟娉曪細

搴忓彿 鏂规硶 鏂规硶绫诲瀷 浣滅敤
1 public CountDownLatch(int count) 鏋勯€犳柟娉?/td> 鏋勯€犲疄渚嬪璞★紝count琛ㄧずCountDownLatch瀵硅薄涓鏁板櫒鐨勫€?/td>
2 public void await() throws InterruptedException 鏅€氭柟娉?/td> 浣挎墍澶勭殑绾跨▼杩涘叆闃诲绛夊緟锛岀洿鍒拌鏁板櫒鐨勫€兼竻闆?/td>
3 public void countDown() 鏅€氭柟娉?/td> 灏嗚鏁板櫒鐨勫€煎噺1
4 public long getCount() 鏅€氭柟娉?/td> 鑾峰彇璁℃暟鍣ㄦ渶鍒濈殑鍊?/td>

馃尭浣跨敤鏂瑰紡锛?/strong>

  • 鍒涘缓CountDownLatch瀵硅薄锛屽苟鍒濆鍖栬鏁板櫒鐨勫€笺€?/li>
  • 鍦ㄦ瘡涓嚎绋嬫墽琛岀殑鏈€鍚庝娇鐢?code>countDown鏂规硶锛岃〃绀哄綋鍓嶇嚎绋嬫墽琛屽畬姣曪紝璁℃暟鍣ㄧ殑鍊煎噺1銆?/li>
  • 鍦ㄤ富绾跨▼涓娇鐢?code>await鏂规硶锛岀瓑寰?code>CountDownLatch瀵硅薄鐨勮鏁板櫒娓呴浂锛岃〃绀烘墍绠$悊鐨勭嚎绋嬪叏閮ㄦ墽琛屽畬姣曪紝璧峰埌绾跨▼鍚屾鐨勪綔鐢ㄣ€?/li>

馃尭鍙傝€冧唬鐮侊細

import java.util.concurrent.*;
public class Main {
    public static final int COUNT = 5;
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(COUNT);

        for (int i = 0; i < COUNT; i++) {
            Thread thread = new Thread(() -> {
                try {
                    Thread.sleep(1000);
                    System.out.println(Thread.currentThread().getName() + "浠诲姟鎵ц瀹屾瘯锛?);
                    countDownLatch.countDown();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            thread.start();
        }
        //绛夊緟璁℃暟鍣ㄦ竻闆讹紝娓呴浂鍓嶏紝绾跨▼澶勪簬闃诲绛夊緟鐘舵€侊紝娓呴浂鍚庯紝鍗冲叏閮ㄤ换鍔℃墽琛屽畬姣?
        countDownLatch.await();
        System.out.println("浠诲姟鍏ㄩ儴瀹屾垚锛?);
    }
}

杩欐牱鐨勫満鏅湪瀹為檯寮€鍙戝綋涓紝涔熸槸寰堝父瑙佺殑锛屾瘮濡傝涓嬭浇涓€涓緝澶х殑鏂囦欢鐨勬椂鍊欙紝甯稿父灏嗘枃浠舵媶鍒嗭紝浣跨敤澶氱嚎绋嬪苟鍙戜笅杞姐€?/p>

鑰屽湪杩欐牱涓€涓満鏅腑锛岄渶瑕佺瓑寰呮渶鍚庝竴涓嚎绋嬩篃涓嬭浇瀹屾瘯锛屾墠鑳借鏁翠釜鏂囦欢涓嬭浇瀹屾瘯锛屼篃灏辨槸浣跨敤CountDownLatch瀵硅薄杩涜璁℃暟锛岀瓑璁℃暟鍣ㄦ竻闆朵簡await鏂规硶灏变細杩斿洖锛岃〃绀烘枃浠朵笅杞藉畬鎴愩€?/p>

馃崅2.5鏈夊叧鏁版嵁缁撴瀯鐨勭嚎绋嬪畨鍏ㄧ被

馃崄2.5.1澶氱嚎绋嬩娇鐢ㄩ『搴忚〃

ArrayList鍦ㄥ绾跨▼涓槸绾跨▼涓嶅畨鍏ㄧ殑锛屽绾跨▼鐜涓娇鐢ㄥ熀浜庡啓瀹炴嫹璐濆疄鐜扮殑CopyOnWriteArrayList銆?/p>

鎵€璋撳啓瀹炴嫹璐濓紝灏辨槸鍐欑殑鏃跺€欎細鍒涘缓涓€涓壇鏈紝鍐嶅壇鏈笂杩涜淇敼锛屽悓鏃跺鏋滃瓨鍦ㄨ鎿嶄綔浼氬湪鍘熸枃浠舵暟杩涜鏌ヨ锛岀瓑淇敼瀹屾瘯鍚庡氨浼氬皢鍓湰鈥滆浆姝b€濄€?/p>

馃崄2.5.2澶氱嚎绋嬩娇鐢ㄩ槦鍒?/h3>

馃尭澶氱嚎绋嬫儏鍐典笅甯稿父浣跨敤闃诲闃熷垪锛?/p>

  1. ArrayBlockingQueue 鍩轰簬鏁扮粍瀹炵幇鐨勯樆濉為槦鍒?/li>
  2. LinkedBlockingQueue 鍩轰簬閾捐〃瀹炵幇鐨勯樆濉為槦鍒?/li>
  3. PriorityBlockingQueue 鍩轰簬鍫嗗疄鐜扮殑甯︿紭鍏堢骇鐨勯樆濉為槦鍒?/li>
  4. TransferQueue 鏈€澶氬彧鍖呭惈涓€涓厓绱犵殑闃诲闃熷垪

馃崄2.5.3澶氱嚎绋嬩娇鐢ㄥ搱甯岃〃

HashMap鏈韩鏄嚎绋嬩笉瀹夊叏鐨勶紝灏咹ashMap涓殑閲嶈鏂规硶浣跨敤synchornized鍔犻攣鍚庯紝灏卞緱鍒颁簡HashTable绫伙紝铏界劧HashTable绫绘槸绾跨▼瀹夊叏鐨勶紝浣嗘槸鐢变簬鏄鏂规硶杩涜鏃犺剳鍔犻攣锛屾湰璐ㄥ姞閿佺殑瀵硅薄鏄疕ashTable绫荤殑瀹炰緥瀵硅薄锛岃繖鏍峰氨浼氬鑷撮攣绔炰簤姒傜巼鍔犲ぇ锛屽氨鐩稿綋浜庡叕鍙搁噷鎵€鏈夌殑鍛樺伐闇€瑕佽鍋囨椂閮介渶瑕佹壘鑰佹澘绛惧瓧鎵瑰噯锛岃繖鏍蜂細瀵艰嚧鑰佹澘闈炲父鍦板繖锛岃繖涓€佹澘灏辩浉褰撲簬鍔犻攣鐨勫搱甯岃〃瀵硅薄锛屾渶缁堜細閫犳垚鍝堝笇琛ㄧ殑鏁堢巼涓嬮檷銆?br> !](https://upload-images.jianshu.io/upload_images/28168001-faf8ed9196403ae5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

涓轰簡瑙e喅杩欎釜闂锛宩ava鎻愪緵浜咰oncurrentHashMap绫伙紝璇ョ被鏄熀浜庡搱甯岃〃涓殑姣忎竴涓摼琛ㄥ璞¤繘琛屽姞閿侊紝绾跨▼闇€瑕佸鍝釜閾捐〃瀵硅薄杩涜鎿嶄綔锛屽氨鍦ㄥ摢閲屽姞閿侊紝鐢变簬鍝堝笇琛ㄤ腑閾捐〃鏁伴噺寰堝锛岄摼琛ㄥ璞$殑鍏冪礌涓暟杈冨皯锛屽彲浠ユ湁鏁堝湴闄嶄綆閿佺珵浜夌殑姒傜巼锛岀浉褰撲簬鍏徃涓殑鑰佹澘灏嗘潈鍔涗笅鏀剧粰鍚勪釜閮ㄩ棬锛屽憳宸ヨ鍋囨椂鍙渶鍚戞墍鍦ㄧ殑閮ㄩ棬棰嗗璇峰亣鍗冲彲銆?/p>

synchronized的优化手段与java中的JUC,第4张

鍒拌繖閲岋紝Java澶氱嚎绋嬫湁鍏冲唴瀹瑰熀鏈笂閮戒粙缁嶅畬姣?/p>


https://www.xamrdz.com/backend/3yg1994616.html

相关文章: