//implements Runable或者extends Thread
public void begin(){
for (int i = 0; i < 5; i++) {
new Thread(new Student()).start();
}
}
private class Student extends Thread{
@Override
public void run() {
try {
Thread.sleep(2000);
System.out.println(Thread.currentThread().getName()+"....");
} catch (Exception e){
e.printStackTrace();
}
System.out.println("==>人到齐了进去吧");
}
}
public ExecutorService threadPool = Executors.newFixedThreadPool(16);
@Test
void contextLoads() {
for (int i = 0; i < 100; i++) {
threadPool.execute(new Runnable(){
@Override
public void run() {
try {
//System.out.println("进来了");
Thread.sleep(100);
//System.out.println("调用了该方法");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
System.out.println(i);
}
//begin();
}
参考:https://blog.csdn.net/weixin_43791937/article/details/103600373