Home > Software engineering >  i am not able to process all the records of a list through the executor's submit method
i am not able to process all the records of a list through the executor's submit method

Time:12-01

Here in this piece of code, i am creating FixedThreadPool = 3, and in the for-loop, my list is carrying 7 records to be processed. For each record to be processed i am assigning its values to msnsfExecutorThread Object that is Autowired at the top. After all the assignments, i am passing the msnsfExecutorThread Object to the submit method that expects a runnable implementation. Now, the issue in my case, is that whenever i reach the run method of msnsfExecutorThread object, it always possesses the details of the last record from the list. Its not working for all the 7 records of the list. How can it work for all the records from the list ?

 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);
        }

CodePudding user response:

you are probably not creating more than 1 msnsfExecutorThread object and keep overriding the data you set .use a concurrent data structure like a concurrentlinkedqueue, set this queue to each msnsfExecutorThread object you create. then in the run() method poll from queue and process.

  • Related