在项目中不能用并发循环类似parallelStream().
BulkOperations bulkOps = mongoTemplate.bulkOps(BulkOperations.BulkMode.ORDERED, Object.class, collectionName); cacheEntities.parallelStream().forEach(comGoods -> { Criteria criteria=Criteria.where("companyId").is(comGoods.getCompanyId()).and("goodsId").is(comGoods.getGoodsId()); Update update = new Update(); //更新内容 update.set("goodsPrice", comGoods.getGoodsPrice()); update.set("goodsSalePrice", comGoods.getGoodsSalePrice()); update.set("goodsMarketPrice", comGoods.getGoodsMarketPrice()); update.set("IntegralPrice", comGoods.getIntegralPrice()); update.set("isShow", comGoods.getIsShow()); update.set("profitRate", comGoods.getProfitRate()); update.set("sort", comGoods.getSort()); update.set("typeId", comGoods.getTypeId()); bulkOps.updateOne(Query.query(criteria), update); });
改成普通的for循环就不会报错