通过多线程实现list数据更新操作

@Override

public Object updateMerchantsToSystem() {

String merchantsList = HttpUtils.sendGet(wx_merchants_url, header_key + "=" + header_value);

if (StringUtils.isNull(merchantsList)) {

return 0;

}

 

List merchantsDTOBean = JSONObject.parseArray(merchantsList, MerchantsDTOBean.class);

Task task = new Task(merchantsDTOBean);

new Thread(task).start(); 

       System.out.println("更新数据完成");

 

return 1;

}

 

class Task implements Runnable{

    

 

    private List list;

    private int num;

     

    public Task(List list){

        this.list = list;

       

    }

    

@Override

public synchronized void run() {

 

for(int i=0;i

MerchantsDTOBean merchantsDTOBean2 = list.get(i);

            //你的处理逻辑

            MerchantsBean merchantsBean = merchantsDao

.getMerhcantsByCode(new MerchantsBean().setMerchants_account(merchantsDTOBean2.getAccount()));

if (merchantsBean != null) {

num = merchantsDao.updateMerchants(new MerchantsBean().setMerchants_id(merchantsBean.getMerchants_id())

.setMerchants_nick_name(merchantsDTOBean2.getName())

.setMerchants_contact_name(merchantsDTOBean2.getName())

.setMerchants_contact_mobile(merchantsDTOBean2.getPhone())

.setMerchants_detail_address(merchantsDTOBean2.getAddress())

.setMerchants_account(merchantsDTOBean2.getAccount())

.setWx_merchants_id(merchantsDTOBean2.getId() + ""));

if (num <= 0) {

throw new AppException("更新错误!");

}

} else {

num = merchantsDao

.insertMerchants(new MerchantsBean().setMerchants_nick_name(merchantsDTOBean2.getName())

.setMerchants_name(merchantsDTOBean2.getName())

.setMerchants_contact_name(merchantsDTOBean2.getName())

.setMerchants_contact_mobile(merchantsDTOBean2.getPhone())

.setMerchants_detail_address(merchantsDTOBean2.getAddress())

.setMerchants_account(merchantsDTOBean2.getAccount())

.setWx_merchants_id(merchantsDTOBean2.getId() + ""));

if (num <= 0) {

throw new AppException("更新错误!");

}

}

        }

 

}

}

}

你可能感兴趣的:(通过多线程实现list数据更新操作)