執行緒池的應用

2021-09-11 14:11:27 字數 1493 閱讀 1750

在專案中,應用到了執行緒池,將**記錄下來,以便將來檢視。

1.獲取案件資訊列表   (controller中的方法  由其他方法呼叫)

public listgetcaseinfolist(jsonarray jsonarray) 

jsonlist = jsonarray.sublist(threadsize * i, datasize);

} else

final listobjectlist = jsonlist;

callable> caseinfocallable = new callable>()

}return caseinfolist;}};

futures.add(executorservice.submit(caseinfocallable));

}for (future> future : futures)

}// 關閉執行緒池

executorservice.shutdown();

} catch (interruptedexception e) catch (executionexception e)

return resultlist;

}

2. 獲取單個案件資訊(由jsp頁面直接呼叫)

@responsebody

public tablemodel caseinfomessage(string id, string casedesc)

// **

string phone = fromtextjson.getstring("phone");

if (stringutils.isnotempty(phone))

// 網路

string network = fromtextjson.getstring("network");

if (stringutils.isnotempty(network)) }}

// 標識提取

url = propertiesutils.getvalue("casedescdicturl");

logger.info(">>>標識提取:" + url);

if (stringutils.isnotempty(url))

}// 小類標識

callable = new caseinfocontroller(url, casedesc, 3);

future = pool.submit(callable);

result = future.get().tostring();

if (stringutils.isnotempty(result)) }}

tablemodel = caseinfoservice.findcaseinflistbyid(id);

} catch (exception e) finally

}return tablemodel;

}

Java執行緒池應用

1.背景 諸如web 伺服器 資料庫伺服器 檔案伺服器或郵件伺服器之類的許多伺服器應用程式都面向處理來自某些遠端 的大量短小的任務。伺服器應用程式中經常出現的情況是 單個任務處理的時間很短而請求的數目卻是巨大的。2.解決方法 構建伺服器應用程式的乙個過於簡單的模型應該是 每當乙個請求到達就建立乙個新...

執行緒池應用實戰

public class threadloadexecuterkeeper implements runnable public void init string thread load else executor.setthreadfactory new processworkerthreadfa...

執行緒池應用例項

利用執行緒池拷貝大檔案 包含資料夾和檔案 opendir mkdir readdir 獲取檔案屬性 stat struct stat s isreg 判斷普通檔案 s isdir 判斷目錄檔案 include include include include include 遞迴讀取目錄 void f...