銆愬師鍒涖€慗ava骞跺彂缂栫▼绯诲垪30 | ThreadLocal
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了銆愬師鍒涖€慗ava骞跺彂缂栫▼绯诲垪30 | ThreadLocal相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/i_1__1_' title='i++'>i++
check 闄愭祦 com 寮傚父 鍝嶅簲 warnings image 鍥炴敹 銆愬師鍒涖€慗ava骞跺彂缂栫▼绯诲垪30 | ThreadLocal
鏀跺綍浜庤瘽棰?br/>#java 976 #绋嬪簭鍛?2286 #骞跺彂缂栫▼ 240 #杩涢樁鏋舵瀯甯?| 骞跺彂缂栫▼涓撻 12
鈽呪槄鈽呭缓璁槦鏍囨垜浠槄鈽呪槄
鍏紬鍙锋敼鐗堝悗鏂囩珷涔卞簭鎺ㄨ崘锛屽笇鏈涗綘鍙互鐐瑰嚮涓婃柟鈥淛ava杩涢樁鏋舵瀯甯堚€濓紝鐐瑰嚮鍙充笂瑙掞紝灏嗘垜浠涓衡槄鈥滄槦鏍団€濓紒杩欐牱鎵嶄笉浼氶敊杩囨瘡鏃ヨ繘闃舵灦鏋勬枃绔犲憖銆?/code>
2020骞碕ava鍘熷垱闈㈣瘯棰樺簱杩炶浇涓?銆?00鏈熴€慗ava鏈€鍏ㄩ潰璇曢搴撴€濈淮瀵煎浘
銆?01鏈熴€慗avaSE闈㈣瘯棰橈紙涓€锛夛細闈㈠悜瀵硅薄
銆?02鏈熴€慗avaSE闈㈣瘯棰橈紙浜岋級锛氬熀鏈暟鎹被鍨嬩笌璁块棶淇グ绗?銆?03鏈熴€慗avaSE闈㈣瘯棰橈紙涓夛級锛欽avaSE璇硶锛?锛?銆?04鏈熴€慗avaSE闈㈣瘯棰橈紙鍥涳級锛欽avaSE璇硶锛?锛?銆?05鏈熴€慗avaSE闈㈣瘯棰橈紙浜旓級锛歋tring绫?銆?06鏈熴€慗avaSE闈㈣瘯棰橈紙鍏級锛氭硾鍨?銆?07鏈熴€慗avaSE闈㈣瘯棰橈紙涓冿級锛氬紓甯?銆?08鏈熴€慗avaSE闈㈣瘯棰橈紙鍏級锛氶泦鍚堜箣List
銆?09鏈熴€慗avaSE闈㈣瘯棰橈紙涔濓級锛氶泦鍚堜箣Set
銆?10鏈熴€慗avaSE闈㈣瘯棰橈紙鍗侊級锛氶泦鍚堜箣Map
銆?11鏈熴€慗avaSE闈㈣瘯棰橈紙鍗佷竴锛夛細澶氱嚎绋嬶紙1锛?銆?12鏈熴€慗avaSE闈㈣瘯棰橈紙鍗佷簩锛夛細澶氱嚎绋嬶紙2锛?銆?13鏈熴€慗avaSE闈㈣瘯棰橈紙鍗佷笁锛夛細澶氱嚎绋嬶紙3锛?銆?14鏈熴€慗avaSE闈㈣瘯棰橈紙鍗佸洓锛夛細鍩烘湰IO娴?銆?15鏈熴€慗avaSE闈㈣瘯棰橈紙鍗佷簲锛夛細缃戠粶IO娴?銆?16鏈熴€慗avaSE闈㈣瘯棰橈紙鍗佸叚锛夛細鍙嶅皠
銆?17鏈熴€慗avaSE闈㈣瘯棰橈紙鍗佷竷锛夛細JVM涔嬪唴瀛樻ā鍨?銆?18鏈熴€慗avaSE闈㈣瘯棰橈紙鍗佸叓锛夛細JVM涔嬪瀮鍦惧洖鏀?銆?20鏈熴€慗avaSE绯诲垪闈㈣瘯棰樻眹鎬伙紙鍏?8绡囷級
銆?19鏈熴€慗avaWeb闈㈣瘯棰橈紙涓€锛夛細JDBC
銆?21鏈熴€慗avaWeb闈㈣瘯棰橈紙浜岋級锛欻TTP鍗忚
銆?22鏈熴€慗avaWeb闈㈣瘯棰橈紙涓夛級锛欳ookie鍜孲ession
銆?23鏈熴€慗avaWeb闈㈣瘯棰橈紙鍥涳級锛欽SP
銆?24鏈熴€慗avaWeb闈㈣瘯棰橈紙浜旓級锛欶ilter鍜孡istener
銆?25鏈熴€慗ava宸ュ叿闈㈣瘯棰橈紙涓€锛夛細鐗堟湰鎺у埗宸ュ叿
銆?26鏈熴€慗ava宸ュ叿闈㈣瘯棰橈紙浜岋級锛氶」鐩鐞嗗伐鍏?銆?27鏈熴€慗ava璁捐妯″紡闈㈣瘯棰?銆?28鏈熴€慗avaWeb绯诲垪闈㈣瘯棰樻眹鎬伙紙鍏?0绡囷級
銆?29鏈熴€慗avaEE闈㈣瘯棰橈紙涓€锛塛eb搴旂敤鏈嶅姟鍣?銆?30鏈熴€慗avaEE闈㈣瘯棰橈紙浜岋級SpringMVC
銆?31鏈熴€慗avaEE闈㈣瘯棰橈紙涓夛級Spring锛?锛?銆?32鏈熴€慗avaEE闈㈣瘯棰橈紙鍥涳級Spring锛?锛?銆?33鏈熴€慗aveEE闈㈣瘯棰橈紙浜旓級MyBatis
銆?34鏈熴€慗avaEE闈㈣瘯棰橈紙鍏級Hibernate
銆?35鏈熴€慗avaEE闈㈣瘯棰橈紙涓冿級SpringBoot锛?锛?鏇村鍐呭锛岀偣鍑讳笂闈㈣摑瀛楁煡鐪?/code>
绾跨▼瀹夊叏闂鐨勬牳蹇冨湪浜庡涓嚎绋嬩細瀵瑰悓涓€涓复鐣屽尯鍏变韩璧勬簮杩涜鎿嶄綔锛岃€屽ぇ澶氭暟瑙e喅绾跨▼瀹夊叏闂鐨勬柟娉曢兘鏄€氳繃鍔犻攣鐨勬柟寮忥紝璁╁悓涓€鏃堕棿鍙湁涓€涓嚎绋嬭兘杩囪闂埌鍏变韩璧勬簮銆傝繖绡囨枃绔犱粙缁嶅彟绉嶈В鍐崇嚎绋嬪畨鍏ㄧ殑鎬濊矾鈥斺€擳hreadLocal锛?br/>浠嬬粛
浣跨敤
婧愮爜
鍐呭瓨娉勯湶
鎬荤粨
1. 浠嬬粛
绾跨▼瀹夊叏闂鐨勬牳蹇冨湪浜庡涓嚎绋嬩細瀵瑰悓涓€涓复鐣屽尯鍏变韩璧勬簮杩涜鎿嶄綔锛屽ぇ澶氭暟瑙e喅绾跨▼瀹夊叏闂鐨勬柟娉曢兘鏄€氳繃鍔犻攣鐨勬柟寮忥紝璁╁悓涓€鏃堕棿鍙湁涓€涓嚎绋嬭兘杩囪闂埌鍏变韩璧勬簮銆?br/>ThreadLocal鎻愪緵浜嗗彟涓€绉嶈В鍐虫€濊矾锛岃姣忎釜绾跨▼鎷ユ湁鑷繁绉佹湁鐨勫唴瀛樼┖闂达紝灏嗙嚎绋嬬鏈夌殑鏁版嵁瀛樺叆杩欎釜绉佹湁绌洪棿鍐咃紝绾跨▼涓庣嚎绋嬩箣闂寸浉浜掗殧绂伙紝杩欐牱灏变笉浼氭湁绾跨▼瀹夊叏闂銆?br/>鏁版嵁缁撴瀯
姣忎釜Thread绾跨▼鍐呴儴閮芥湁涓€涓猅hreadLocalMap鍙橀噺threadLocals锛岃繖涓猼hreadLocals灏辨槸杩欎釜绾跨▼鐨勭鏈夌┖闂淬€?br/>threadLocals鏄竴涓猭ey-value鐨刴ap缁撴瀯锛宬ey鏄疶hreadLoacal瀵硅薄锛寁alue灏辨槸绾跨▼闇€瑕佷繚瀛樼殑绉佹湁鏁版嵁銆?br/>
2. 浣跨敤
ThreadLocal鏍稿績鏂规硶锛?br/>get()锛氳繑鍥炲綋鍓嶇嚎绋嬪壇鏈腑璇hreadLocal瀵瑰簲鐨勫€笺€?br/>initialValue()锛氳繑鍥炲綋鍓嶇嚎绋嬪壇鏈腑鐨勮ThreadLocal瀵瑰簲瀵瑰簲鐨勨€滃垵濮嬪€尖€濄€?br/>remove()锛氱Щ闄ゅ綋鍓嶇嚎绋嬪壇鏈腑璇hreadLocal瀵瑰簲鐨勫€笺€?br/>set(T value)锛氬綋鍓嶇嚎绋嬪壇鏈腑璇hreadLocal瀵瑰簲鐨勫€间负value銆?br/>浣跨敤涓句緥锛?br/>姣忎釜绾跨▼淇濆瓨涓€涓鏈夌殑int鍊糲ount锛?涓嚎绋媍ount浠?鍔犲埌10锛岀嚎绋嬩箣闂翠簰涓嶅奖鍝嶃€?/p>
/**
* 姣忎釜绾跨▼淇濆瓨涓€涓鏈夌殑int鍊糲ount
* 5涓嚎绋媍ount浠?鍔犲埌10锛岀嚎绋嬩箣闂翠簰涓嶅奖鍝? */
public class ThreadLocalDemo {
private static ThreadLocal<Integer> countLocal = new ThreadLocal<Integer>(){
public Integer initialValue() {
return 0;
}
};
public static void main(String[] args){
for (int i = 1; i <= 5; i++) {
new Thread("Thread_" + i) {
public void run() {
for (int j = 1; j <= 10; j++) {
countLocal.set(countLocal.get() + 1);
System.out.println(getName() + ": count=" + countLocal.get());
}
};
}.start();
}
}
}
杈撳嚭缁撴灉濡備笅锛?/p>
Thread_3: count=1
Thread_5: count=1
Thread_5: count=2
Thread_4: count=1
Thread_4: count=2
Thread_2: count=1
Thread_2: count=2
Thread_2: count=3
Thread_2: count=4
Thread_1: count=1
Thread_2: count=5
Thread_4: count=3
Thread_5: count=3
Thread_5: count=4
Thread_3: count=2
Thread_5: count=5
Thread_5: count=6
Thread_5: count=7
Thread_5: count=8
Thread_4: count=4
Thread_4: count=5
Thread_4: count=6
Thread_2: count=6
Thread_2: count=7
Thread_2: count=8
Thread_2: count=9
Thread_1: count=2
Thread_2: count=10
Thread_4: count=7
Thread_5: count=9
Thread_3: count=3
Thread_3: count=4
Thread_5: count=10
Thread_4: count=8
Thread_1: count=3
Thread_4: count=9
Thread_3: count=5
Thread_4: count=10
Thread_1: count=4
Thread_3: count=6
Thread_1: count=5
Thread_3: count=7
Thread_1: count=6
Thread_3: count=8
Thread_1: count=7
Thread_3: count=9
Thread_1: count=8
Thread_3: count=10
Thread_1: count=9
Thread_1: count=10
鍙互鐪嬪埌锛屽嵆浣?涓嚎绋嬪苟鍙戞墽琛岋紝浣嗘槸姣忎釜绾跨▼鍐呴儴鐨刢ount閮芥槸鎸?-10鐨勯『搴忕浉鍔犵殑銆?/p>
3. 婧愮爜
3.1 鏁版嵁缁撴瀯
姣忎釜Thread绾跨▼鍐呴儴閮芥湁涓€涓猅hreadLocalMap鍙橀噺threadLocals锛岃繖涓猼hreadLocals灏辨槸杩欎釜绾跨▼鐨勭鏈夌┖闂淬€?br/>threadLocals鏄竴涓猭ey-value鐨刴ap缁撴瀯锛宬ey鏄疶hreadLoacal瀵硅薄锛寁alue灏辨槸绾跨▼闇€瑕佷繚瀛樼殑绉佹湁鏁版嵁銆?/p>
/**
* 绾跨▼灞€閮ㄥ彉閲弔hreadLocals涓篢hreadLocal.ThreadLocalMap绫诲瀷
*/
public class Thread implements Runnable {
ThreadLocal.ThreadLocalMap threadLocals = null;
}
/**
* ThreadLocal$ThreadLocalMap 鏁e垪琛ㄧ粨鏋? * key=ThreadLocal value=Object
*/
static class ThreadLocalMap {
private Entry[] table;
static class Entry extends WeakReference<ThreadLocal<?>> {
/** The value associated with this ThreadLocal. */
Object value;
Entry(ThreadLocal<?> k, Object v) {
super(k);
value = v;
}
}
}
3.2 get()
鍦ㄧ悊瑙g殑ThreadLocal鐨勫瓨鍌ㄧ粨鏋勪箣鍚庯紝鍐嶇湅get()鍜宻et()鏂规硶灏卞緢绠€鍗曚簡銆?br/>get()锛?br/>鑾峰彇褰撳墠绾跨▼thread銆?br/>鑾峰彇褰撳墠绾跨▼thread.threadLocals锛宼hreadLocals鏄痬ap缁撴瀯銆?br/>map鐨刱ey鏄疶hreadLocal绫诲瀷锛岃幏鍙杕ap涓綋鍓峵hreadLocal瀵瑰簲鐨剉alue鍊笺€?br/>濡傛灉map=null锛屽氨鍒涘缓map骞惰祴鍒濆€笺€?/p>
public T get() {
// 鑾峰彇褰撳墠绾跨▼绉佹湁鐨刴ap thread.threadLocals
Thread t = Thread.currentThread();
ThreadLocalMap map = getMap(t);
// 鑾峰彇map鐨剉alue鍊? if (map != null) {
// map鐨刱ey鏄疶hreadLocal绫诲瀷
ThreadLocalMap.Entry e = map.getEntry(this);
if (e != null) {
@SuppressWarnings("unchecked")
T result = (T)e.value;
return result;
}
}
// 濡傛灉map=null锛屽垵濮嬪寲map锛屼笅鏂囨湁璁茶В
return setInitialValue();
}
/**
* 杩斿洖ThreadLocalMap绫诲瀷鐨則hread.threadLocals
*/
ThreadLocalMap getMap(Thread t) {
return t.threadLocals;
}
/**
* 鍒濆鍖杤alue锛宮ap=null鏃朵細鍒濆鍖杕ap
*/
private T setInitialValue() {
T value = initialValue();// 鍒濆鍊? Thread t = Thread.currentThread();
ThreadLocalMap map = getMap(t);
if (map != null)
map.set(this, value);// 灏嗗垵濮嬪€煎瓨鍏ap
else
createMap(t, value);// map=null鏃跺垵濮嬪寲map
return value;
}
/**
* 杩斿洖map涓璿alue鐨勫垵濮嬪€? * 榛樿涓簄ull锛屼竴鑸渶瑕侀噸鍐欒鏂规硶浠ヨ幏寰楅潪null鍊? */
protected T initialValue() {
return null;
}
set()锛?br/>鑾峰彇褰撳墠绾跨▼thread銆?br/>鑾峰彇褰撳墠绾跨▼thread.threadLocals锛宼hreadLocals鏄痬ap缁撴瀯銆?br/>map鐨刱ey鏄疶hreadLocal绫诲瀷锛岃缃甿ap涓綋鍓峵hreadLocal瀵瑰簲鐨剉alue鍊笺€?br/>濡傛灉map=null锛屽氨鍒涘缓map骞惰祴鍊笺€?/p>
public void set(T value) {
Thread t = Thread.currentThread();
ThreadLocalMap map = getMap(t);
if (map != null)
map.set(this, value);
else
createMap(t, value);
}
4. 娉ㄦ剰闂
4.1 姣忎釜绾跨▼鏈€濂藉彧瀛樹竴涓猅hreadLocal
绾挎€ф帰娴嬭В鍐矵ash鍐茬獊锛氭牴鎹垵濮媖ey鐨刪ashcode鍊肩‘瀹氬厓绱犲湪table鏁扮粍涓殑浣嶇疆锛屽鏋滃彂鐜拌繖涓綅缃笂宸茬粡鏈夊叾浠杒ey鍊肩殑鍏冪礌琚崰鐢紝鍒欏埄鐢ㄥ浐瀹氱殑绠楁硶瀵绘壘涓€瀹氭闀跨殑涓嬩釜浣嶇疆锛屼緷娆″垽鏂紝鐩磋嚦鎵惧埌鑳藉瀛樻斁鐨勪綅缃€?/p>
ThreadLocalMap涓В鍐矵ash鍐茬獊鐨勬柟寮忓苟闈為摼琛ㄧ殑鏂瑰紡锛岃€屾槸閲囩敤绾挎€ф帰娴嬬殑鏂瑰紡锛屾墍璋揟hreadLocalMap瑙e喅Hash鍐茬獊鐨勬柟寮忓氨鏄畝鍗曠殑姝ラ暱鍔?鎴栧噺1锛屽鎵句笅涓€涓浉閭荤殑浣嶇疆銆?br/>濡備笅锛孴hreadLocalMap.set()鏂规硶锛?/p>
private void set(ThreadLocal<?> key, Object value) {
// 鏍规嵁 ThreadLocal 鐨勬暎鍒楀€硷紝鏌ユ壘瀵瑰簲鍏冪礌鍦ㄦ暟缁勪腑鐨勪綅缃? Entry[] tab = table;
int len = tab.length;
int i = key.threadLocalHashCode & (len-1);
// 閲囩敤绾挎€ф帰娴嬫硶锛屽鎵惧悎閫備綅缃? for (Entry e = tab[i];
e != null;
e = tab[i = nextIndex(i, len)]) {
ThreadLocal<?> k = e.get();
// key 瀛樺湪锛岀洿鎺ヨ鐩? if (k == key) {
e.value = value;
return;
}
/*
* key=null鑰寁alue!=null锛屽洜涓簁ey鏄急寮曠敤
* 鐢ㄦ柊鐨刱ey-value灏嗘棫鐨刵ull-value鏇挎崲鎺? */
if (k == null) {
replaceStaleEntry(key, value, i);
return;
}
}
tab[i] = new Entry(key, value);
int sz = ++size;
// 娓呴櫎闄堟棫鐨凟ntry锛坘ey == null锛? if (!cleanSomeSlots(i, sz) && sz >= threshold)
rehash();
}
ThreadLocalMap閲囩敤绾挎€ф帰娴嬬殑鏂瑰紡瑙e喅Hash鍐茬獊鐨勬晥鐜囧緢浣庯紝濡傛灉鏈夊ぇ閲忎笉鍚岀殑ThreadLocal瀵硅薄鏀惧叆map涓椂鍙戦€佸啿绐侊紝鎴栬€呭彂鐢熶簩娆″啿绐侊紝鍒欐晥鐜囧緢浣庛€傛墍浠ユ瘡涓嚎绋嬫渶濂藉彧瀛楾hreadLocal銆?br/>4.2 寮曞彂鍐呭瓨娉勯湶
ThreadLocal浣跨敤涓細鏈夊唴瀛樻硠闇查棶棰樸€?br/>ThreadLocalMap鐨刱ey鏄急寮曠敤锛岃€孷alue鏄己寮曠敤銆傛簮鐮佸涓嬶細
static class ThreadLocalMap {
static class Entry extends WeakReference<ThreadLocal<?>> {
Object value;
Entry(ThreadLocal<?> k, Object v) {
super(k);
value = v;
}
}
}
ThreadLocalMap鐨刱ey鏄急寮曠敤锛屽彂鐢烥C鏃跺急寮曠敤key浼氳鍥炴敹锛涜€寁alue鏄己寮曠敤锛孏C鏃朵笉浼氳鍥炴敹銆?br/>鎵€浠hreadLocalMap涓氨浼氬嚭鐜発ey涓簄ull鐨凟ntry锛屽洜涓簁ey涓簄ull锛岃繖Entry鏄笉鑳借璁块棶鍒扮殑銆傚鏋滃綋鍓嶇嚎绋嬩竴鐩存病缁撴潫鐨勮瘽锛屼竴鐩存湁杩欎釜寮曠敤閾撅細Thread --寮曠敤--> ThreaLocalMap --寮曠敤--> Entry --寮曠敤--> value锛岃繖涓獀alue灏辨棤娉曡鍥炴敹锛屽鑷村唴瀛樻硠闇层€?br/>瑙e喅锛?br/>ThreadLocalMap鐨剆et()銆乧leanSomeSlots()绛夋柟娉曚腑閮藉仛浜嗙浉搴斿鐞嗭紝妫€鏌ュ瓨鍦╧ey=null鑰寁alue!=null鐨凟ntry灏变細鍒犳帀锛?br/>鍦ㄨ皟鐢═hreadLocal鐨刧et()銆乻et()鏂规硶鏃跺畬鎴愬悗鍐嶈皟鐢╮emove鏂规硶锛屽皢Entry鑺傜偣鍜孧ap鐨勫紩鐢ㄥ叧绯荤Щ闄わ紝杩欐牱鏁翠釜Entry瀵硅薄鍦℅C Roots鍒嗘瀽鍚庡氨鍙樻垚涓嶅彲杈句簡锛屼笅娆C鐨勬椂鍊欏氨鍙互琚洖鏀躲€?/p>
5. 鎬荤粨
鍚屾鏈哄埗 VS ThreadLocal
鍚屾鏈哄埗鏄€氳繃鎺у埗绾跨▼璁块棶鍏变韩瀵硅薄鐨勯『搴忥紝绫讳技鈥滄椂闂存崲绌洪棿鈥濓紝鍚屼竴鏃跺埢鍏变韩瀵硅薄鍙兘琚竴涓嚎绋嬭闂€犳垚鏁翠綋涓婂搷搴旀椂闂村鍔狅紝浣嗘槸瀵硅薄鍙崰鏈変竴浠藉唴瀛樸€?br/>鑰孴hreadLocal鏄负姣忎竴涓嚎绋嬪垎閰嶄竴涓瀵硅薄锛屽悇鐢ㄥ悇鐨勪簰涓嶅奖鍝嶃€傜被浼尖€滅┖闂存崲鏃堕棿鈥濓紝涓烘瘡涓嚎绋嬮兘鍒嗛厤浜嗕竴浠藉璞★紝鑷劧鑰岀劧鍐呭瓨浣跨敤鐜囧鍔狅紝浣嗘暣浣撲笂鏃堕棿鏁堢巼瑕佸鍔犲緢澶氥€?br/>ThreadLocal瀛樺偍缁撴瀯
姣忎釜Thread绾跨▼鍐呴儴閮芥湁涓€涓猅hreadLocalMap鍙橀噺threadLocals锛岃繖涓猼hreadLocals灏辨槸杩欎釜绾跨▼鐨勭鏈夌┖闂淬€?br/>threadLocals鏄竴涓猭ey-value鐨刴ap缁撴瀯锛宬ey鏄疶hreadLoacal瀵硅薄锛寁alue灏辨槸绾跨▼闇€瑕佷繚瀛樼殑绉佹湁鏁版嵁銆?br/>娉ㄦ剰闂
ThreadLocalMap閲囩敤绾挎€ф帰娴嬬殑鏂瑰紡瑙e喅Hash鍐茬獊鐨勬晥鐜囧緢浣庯紝濡傛灉鏈夊ぇ閲忎笉鍚岀殑ThreadLocal瀵硅薄鏀惧叆map涓椂鍙戦€佸啿绐侊紝鎴栬€呭彂鐢熶簩娆″啿绐侊紝鍒欐晥鐜囧緢浣庛€傛墍浠ユ瘡涓嚎绋嬫渶濂藉彧瀛楾hreadLocal銆?br/>鐢变簬ThreadLocalMap鐨刱ey鏄急寮曠敤锛孴hreadLocal浣跨敤涓細鏈夊唴瀛樻硠闇查棶棰樸€傚湪浣跨敤瀹孴hreadLocal涔嬪悗璋冪敤remove鏂规硶鍒犻櫎鍊硷紝鍙伩鍏嶅唴瀛樻硠闇查棶棰樸€?/p>
骞跺彂绯诲垪鏂囩珷姹囨€?/h1>
銆愬師鍒涖€?1|寮€绡囪幏濂栨劅瑷€
銆愬師鍒涖€?2|骞跺彂缂栫▼涓夊ぇ鏍稿績闂
銆愬師鍒涖€?3|閲嶆帓搴?鍙鎬у拰鏈夊簭鎬ч棶棰樻牴婧?br/>銆愬師鍒涖€?4|Java 鍐呭瓨妯″瀷璇﹁В
銆愬師鍒涖€?5|娣卞叆鐞嗚В volatile
銆愬師鍒涖€?6|浣犱笉鐭ラ亾鐨?final
銆愬師鍒涖€?7|synchronized 鍘熺悊
銆愬師鍒涖€?8|synchronized 閿佷紭鍖?br/>銆愬師鍒涖€?9|鍩虹骞茶揣
銆愬師鍒涖€?0|绾跨▼鐘舵€?br/>銆愬師鍒涖€?1|绾跨▼璋冨害
銆愬師鍒涖€?2|鎻 CAS
銆愬師鍒涖€?3|LockSupport
銆愬師鍒涖€?4|AQS 婧愮爜鍒嗘瀽
銆愬師鍒涖€?5|閲嶅叆閿?ReentrantLock
銆愬師鍒涖€?6|鍏钩閿佷笌闈炲叕骞抽攣
銆愬師鍒涖€?7|璇诲啓閿佸叓璁诧紙涓婏級
銆愬師鍒涖€?8|璇诲啓閿佸叓璁诧紙涓嬶級
銆愬師鍒涖€?9|JDK8鏂板閿丼tampedLock
銆愬師鍒涖€?0|StampedLock婧愮爜瑙f瀽
銆愬師鍒涖€?1|Condition-Lock鐨勭瓑寰呴€氱煡
銆愬師鍒涖€?2|鍊掕鏃跺櫒CountDownLatch
銆愬師鍒涖€?2|鍊掕鏃跺櫒CountDownLatch
銆愬師鍒涖€?3|寰幆灞忛殰CyclicBarrier
銆愬師鍒涖€?4|淇″彿閲廠emaphore
銆愬師鍒涖€?5|浜ゆ崲鍣‥xchangere
銆愬師鍒涖€?6|ConcurrentHashMap锛堜笂锛?br/>銆愬師鍒涖€?7|ConcurrentHashMap锛堜笅锛?br/>銆愬師鍒涖€?8|Copy-On-Write瀹瑰櫒
涔嬪墠锛岀粰澶у鍙戣繃涓変唤Java闈㈣瘯瀹濆吀锛岃繖娆℃柊澧炰簡涓€浠斤紝鐩墠鎬诲叡鏄洓浠介潰璇曞疂鍏革紝鐩镐俊鍦ㄨ烦妲藉墠涓€涓湀鎸夌収闈㈣瘯瀹濆吀鍑嗗鍑嗗锛屽熀鏈病澶ч棶棰樸€?br/>銆妀ava闈㈣瘯瀹濆吀5.0銆?鍒濅腑绾?
銆?50閬揓ava闈㈣瘯棰橈細鏁寸悊鑷?00+鍏徃銆嬶紙涓珮绾э級
銆婅祫娣眏ava闈㈣瘯瀹濆吀-瑙嗛鐗堛€嬶紙璧勬繁锛?br/>銆奐ava[BAT]闈㈣瘯蹇呭銆嬶紙璧勬繁锛?br/>鍒嗗埆閫傜敤浜庡垵涓骇锛屼腑楂樼骇锛岃祫娣辩骇宸ョ▼甯堢殑闈㈣瘯澶嶄範銆?br/>鍐呭鍖呭惈java鍩虹銆乯avaweb銆乵ysql鎬ц兘浼樺寲銆丣VM銆侀攣銆佺櫨涓囧苟鍙戙€佹秷鎭槦鍒楋紝楂樻€ц兘缂撳瓨銆佸弽灏勩€丼pring鍏ㄥ妗跺師鐞嗐€佸井鏈嶅姟銆乑ookeeper銆佹暟鎹粨鏋勩€侀檺娴佺啍鏂檷绾х瓑绛夈€?br/>
鑾峰彇鏂瑰紡锛氱偣鈥滃湪鐪嬧€濓紝V淇″叧娉ㄤ笂杩癑ava鏈€鍏ㄩ潰璇曢搴撳彿骞跺洖澶?銆愰潰璇曘€戝嵆鍙鍙栵紝鏇村绮惧僵闄嗙画濂変笂銆?/p>
鐪嬪埌杩欓噷锛岃瘉鏄庢湁鎵€鏀惰幏
蹇呴』鐐逛釜鍦ㄧ湅鏀寔鍛€锛屽柕
以上是关于銆愬師鍒涖€慗ava骞跺彂缂栫▼绯诲垪30 | ThreadLocal的主要内容,如果未能解决你的问题,请参考以下文章