多线程:指的是这个程序(一个进程)运行时产生了不止一个线程。更好的利用cpu资源
简单的例子实现多线程如下:
@Service
public class TestDemoImpl implements TestDemoService{
@Autowired
private Dao dao;
@Override
public void test(){
Mythread mythread = new Mythread(dao);
Thread thread = new Thread(mythread);
mythread.start();
}
}
自定义线程类
public class Mythread implements Runnable(){
private Dao dao;
public Mythread(Dao dao){
this.dao = dao ;
}
@Override
public void run(){
...
业务代码
...
}
}