ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ package thread.a2; public class Test { public static void main(String[] args){ Xc3 xc31=new Xc3(); xc31.setName("线程1"); xc31.start(); Xc3 xc32=new Xc3(); xc32.setName("线程2"); xc32.start(); Xc3 xc33=new Xc3(); xc33.setName("线程3"); xc33.start(); System.out.println( Thread.currentThread().getName()+"在执行"); } } class Xc3 extends Thread { public void run() { System.out.println( Thread.currentThread().getName()+"在执行"); } //显示当前线程名称 } ~~~ ![](https://box.kancloud.cn/c4c02ad2a47853974960639f1eed6b08_139x128.png) ~~~ package thread.a2; public class Test1 { public static void main(String[] args) { Thread xc1 = new Thread(new Xc41()); Thread xc2 = new Thread(new Xc42());//线程默认级别是5 xc2.setPriority(Thread.NORM_PRIORITY + 3); //数字越大优先级越高 xc1.start(); xc2.start(); } } class Xc41 implements Runnable { public void run() { for(int i=0; i<100; i++) { System.out.println("1线程" + i); } } } class Xc42 implements Runnable { public void run() { for(int i=0; i<100; i++) { System.out.println("第2个线程正在被执行: " + i); } } } ~~~ ![](https://box.kancloud.cn/174b4bc5b0d9ef1e6f55962fae863c18_285x318.png) ~~~ 设置了优先级只是相对要高点,并不是绝对要高 ~~~