在這段代碼中,我創建了FixedThreadPool = 3,并且在for回圈中,我的串列攜帶了7條要處理的記錄。對于要處理的每條記錄,我將其值分配給頂部自動裝配的 msnsfExecutorThread 物件。在所有分配之后,我將 msnsfExecutorThread 物件傳遞給需要可運行實作的提交方法。現在,就我而言,問題是每當我到達 msnsfExecutorThread 物件的 run 方法時,它總是擁有串列中最后一條記錄的詳細資訊。它不適用于串列的所有 7 條記錄。它如何適用于串列中的所有記錄?
ExecutorService executor = Executors.newFixedThreadPool(3);
for (TempMSISDNCollectFee tempMSISDNCollectFee : list) {
msnsfExecutorThread.setGcsAccountId(tempMSISDNCollectFee.getGcsAccountId());
msnsfExecutorThread.setMsisdn(tempMSISDNCollectFee.getMsisdn());
msnsfExecutorThread.setProcessStatus(tempMSISDNCollectFee.getProcessingStatus());
msnsfExecutorThread.setPartnerCode(tempMSISDNCollectFee.getPartnerCode());
executor.submit(msnsfExecutorThread);
}
uj5u.com熱心網友回復:
您可能不會創建超過 1 個 msnsfExecutorThread 物件并繼續覆寫您設定的資料。使用并發資料結構(如 concurrentlinkedqueue),將此佇列設定為您創建的每個 msnsfExecutorThread 物件。然后在 run() 方法中從佇列和行程輪詢。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/371833.html
