package hu;
import java.io.IOException;
import java.util.Scanner ;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class 软件1901学号193401040108刘宗佑作业1 {

static class MusicThread extends Thread{ //MusicThread是线程子类
public void run() { //子类必须重写run()方法
for(int i = 0 ;i < 5;i++)
{System.out.println(“听音乐”+i);}

try {
try {
Thread.currentThread().sleep(10);

} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();

}
System.out.println(“睡了”);
IOException e = new IOException();
throw e;

} catch (IOException e1) {

// TODO Auto-generated catch block
e1.printStackTrace();
System.out.println(“睡醒了”);
}

}}

public static void main(String arg[]) throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(5);
for(int i=0;i<3;i++) {
MusicThread t = new MusicThread(); //创建线程子类的实例
executor.execute(t);
}
executor.shutdown();

}

}

版权声明:本文为祥瑞哈哈哈原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/hahaah/p/16127079.html