Ⅰ 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 鍖呫