spring boot环境,在service里调用线程,线程执行一条s
[*]service层代码
UserService service;@Autowired
public void setService(UserService service) {
this.service = service;
}
@Override
public void add(User user) {
System.out.println(mapper);
Thread thread = new Thread(new MyRunnable(mapper, user));
thread.start();
}
class MyRunnable implements Runnable {
UserMapper mapper;
User user;
public MyRunnable(UserMapper mapper, User user) {
this.mapper = mapper;
this.user = user;
System.out.println(mapper);
System.out.println(user);
}
@Override
public void run() {
mapper.insert(user);
}
}
@Test
public void test1() {
User u1 = new User(1L,"A");
service.add(u1);
}
控制台输出
数据库确没数据,又不报错。
加个等待时间,数据库插入需要时间。 程序结束太早,数据库插入需要时间 程序结束的太早了,数据库插入式需要时间的,最后sleep下 查询后输出
页:
[1]