给下面代码添加注释public class Demo1 { public static void main(String[] args) { TicketThread1 ticketThread=new TicketThread1(); Thread t1=new Thread(ticketThread,"窗口1"); Thread t2=new Thread(ticketThread,"窗口2"); Thread t3=new Thread(ticketThread,"窗口3"); // t2.setPriority(10); t3.setPriority(1); t1.start(); t2.start(); t3.start(); } }
时间: 2024-04-26 17:22:57 浏览: 34
java代码-demo1code
// 定义一个名为Demo1的公共类
public class Demo1 {
// 程序入口main方法
public static void main(String[] args) {
// 创建一个TicketThread1对象,该对象实现了Runnable接口
TicketThread1 ticketThread=new TicketThread1();
// 创建三个线程对象t1、t2、t3,它们都使用同一个TicketThread1对象
Thread t1=new Thread(ticketThread,"窗口1");
Thread t2=new Thread(ticketThread,"窗口2");
Thread t3=new Thread(ticketThread,"窗口3");
// 设置线程t2的优先级为最高,即10,t3的优先级为最低,即1
t2.setPriority(10);
t3.setPriority(1);
// 启动三个线程
t1.start();
t2.start();
t3.start();
}
}
阅读全文