Ⅰ java.util.concurrent镓ц岀▼搴
Java涓镄刯ava.util.concurrent鍖呮彁渚涗简涓绉嶅己澶х殑宸ュ叿锛岀敤浜庣粍缁囧拰绠$悊澶嶆潅镄勬墽琛岀▼搴忋傛牳蹇冩帴鍙f槸Executor锛屽畠瀹氢箟浜嗕竴涓鎶借薄镄勬嗘灦锛屾敮鎸佽嚜瀹氢箟绾跨▼绯荤粺锛屽寘𨰾绾跨▼姹犮佸纾姝I/O镎崭綔锛屼互鍙婅交閲忕骇浠诲姟澶勭悊銆傞氲繃浣跨敤涓嶅悓绫诲瀷镄凟xecutor瀹炰緥锛屼换锷″彲浠ュ湪鏂板垱寤虹殑绾跨▼锛屽凡瀛桦湪镄勪换锷℃墽琛岀嚎绋嬶纴鎴栬呰皟鐢╡xecute()镄勭嚎绋嬩腑杩愯岋纴镓ц屾柟寮忓彲浠ユ槸椤哄簭鎴栧苟鍙戠殑銆
ExecutorService鏄疎xecutor镄勪竴涓镓╁𪾢锛屽畠鎻愪緵浜嗗畬鏁寸殑寮傛ヤ换锷$$悊锷熻兘銆傚畠璐熻矗浠诲姟镄勬帓阒熷拰璋冨害锛屽苟鍏佽哥敤鎴锋带鍒跺叾鐢熷懡锻ㄦ湡镄勭粓姝銆傝繖镒忓懗镌浣犲彲浠ュ垱寤轰竴涓鎸佷箙镄勫伐浣灭嚎绋嬫睁锛岀敤浜庨珮鏁埚湴镓ц岄吨澶崭换锷°
杩涗竴姝ワ纴ScheledExecutorService浣滀负ExecutorService镄勫瓙鎺ュ彛锛屽炲姞浜嗗瑰欢杩熷拰瀹氭湡浠诲姟镄勬敮鎸併傝繖镒忓懗镌浣犲彲浠ュ畨鎺掍换锷″湪鐗瑰畾镄勬椂闂寸偣镓ц岋纴鎴栬呮寜镦т竴瀹氱殑锻ㄦ湡閲嶅嶆墽琛岋纴杩椤逛簬瀹氭椂浠诲姟鍜屽懆链熸у伐浣滈潪甯告湁鐢ㄣ
浣跨敤ExecutorService镄勪竴涓鍏抽敭鐗规ф槸鍏跺笴allable鍜孯unnable镄勬敮鎸併傞氲繃execute()鏂规硶锛屼綘鍙浠ユ彁浜や竴涓琛ㄧず璁$畻浠诲姟镄凛allable锛屽畠涓崭粎镓ц屾搷浣滐纴杩樿兘杩斿洖涓涓缁撴灉銆傝繖镙凤纴浣犱笉浠呭彲浠ュ惎锷ㄤ竴涓寮傛ユ搷浣滐纴杩桦彲浠ヨ幏鍙栧叾镓ц岀粨鏋溿傚悓镞讹纴Future瀵硅薄鎻愪緵浜嗘镆ヤ换锷″畬鎴愮姸镐佷互鍙婂彇娑堜换锷$殑鏂规硶锛屽炲己浜嗕换锷℃带鍒剁殑𨱔垫椿镐с
java.util.concurrent 鏄鍦ㄥ苟鍙戠紪绋嬩腑寰埚父鐢ㄧ殑瀹炵敤宸ュ叿绫汇傛ゅ寘鍖呮嫭浜嗗嚑涓灏忕殑銆佸凡镙囧嗳鍖栫殑鍙镓╁𪾢妗嗘灦锛屼互鍙娄竴浜涙彁渚涙湁鐢ㄥ姛鑳界殑绫伙纴娌℃湁杩欎簺绫伙纴杩欎簺锷熻兘浼氩緢闅惧疄鐜版垨瀹炵幇璧锋潵鍐楅暱涔忓懗銆备笅闱㈢亩瑕佹弿杩颁富瑕佺殑缁勪欢銆傚彟璇峰弬阒 locks 鍜 atomic 鍖呫