Day 9:多线程
多线程可以提高应用程序的性能和响应速度。以下是一个简单的Java程序,可以帮助我们创建和执行多线程:
javaCopy Codepublic class MultiThread {
private static final int THREAD_COUNT = 5;
public static void main(String[] args) {
for (int i = 0; i < THREAD_COUNT; i++) {
Thread thread = new Thread(new MyRunnable(i));
thread.start();
}
}
private static class MyRunnable implements Runnable {
private int id;
public MyRunnable(int id) {
this.id = id;
}
@Override
public void run() {
System.out.println("线程" + id + "开始执行!");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("线程" + id + "执行完毕!");
}
}
}
标签:int,private,public,static,冲刺,多线程,id From: https://www.cnblogs.com/2574999647wyx/p/17473104.html