java 进程的参数和list的线程安全

2021-05-29 23:04

阅读:421

implements Runnable {

@Autowired
private MongoTemplate mongoTemplate;

private static Listlist = new CopyOnWriteArrayList();//静态变量

public static Logger logger = LoggerFactory.getLogger(RobotRun.class);

public RobotRun(List list1) {//构造函数
list=list1;
mongoTemplate = (MongoTemplate) AllBeanService.getBean(MongoTemplate.class);
}

@Override
public void run() {
logger.info("list:"+list.size());
mongoTemplate.insert(list,"robot");
list.clear();
logger.info("添加成功:"+list.size());
}

public void setList(List list) {
this.list = list;
}
}


评论


亲,登录后才可以留言!