在项目中不能用并发循环类似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循环就不会报错
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。