第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

瘋狂java中ForjoinPool線程池中拆分的問題。

瘋狂java中ForjoinPool線程池中拆分的問題。

慕粉4241372 2017-03-16 16:53:27
class?CalTask?extends?RecursiveTask<Integer>{ ??private?static?final?int?THRESHOLD=20; ????private?int?arr[]; ????private?int?start; ????private??int?end; ????public?CalTask(int[]?arr,?int?start,?int?end)?{ super(); this.arr?=?arr; this.start?=?start; this.end?=?end; ????} ????@Override ????protected?Integer?compute()?{ int?sum=0; if?(end-start<THRESHOLD)?{ ????for?(int?i?=?start;?i?<?end;?i++)?{ ????????????sum?+=?arr[i]; ????} ????return?sum; ????}?else?{ ????int?middle=(start+end)/2; ????CalTask?left=new?CalTask(arr,?start,?middle); ????CalTask?ringht=new?CalTask(arr,?middle,?end); ????left.fork(); ????ringht.fork(); ????return?left.join()+ringht.join(); ?????} ????} } public?class?Sum?{ ????public?static?void?main(String[]?args)?throws?InterruptedException,?ExecutionException?{ int[]?arr?=?new?int[100]; Random?rand?=?new?Random(); int?total?=?0; for?(int?i?=?0;?i?<?arr.length;?i++)?{ int?tmp=rand.nextInt(20); total+=(arr[i]=tmp); } System.out.println(total); ForkJoinPool?pool=ForkJoinPool.commonPool(); Future<Integer>?future?=?pool.submit(new?CalTask(arr,0,arr.length)); System.out.println(future.get()); pool.shutdown(); ????} }無返回值的情況下已經(jīng)搞懂了但像這樣有返回值的情況下,compute方法else塊中最后 return left.join()+right.join();理解不了,請大神通俗的解釋一下另外這里fork()方法能說明一下嗎?書中居然沒有說,看例子就是執(zhí)行的意思?還有commPool的運行狀態(tài)不是說不受shutdown()影響嗎?那這里為何要有這個方法?
查看完整描述

2 回答

?
慕粉4241372

TA貢獻2條經(jīng)驗 獲得超1個贊

另外這里fork()方法能說明一下嗎?書中居然沒有說,看例子就是執(zhí)行的意思?

查看完整回答
反對 回復(fù) 2017-03-16
  • 2 回答
  • 0 關(guān)注
  • 1747 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號