/*
- 线程睡眠
*/
package com.fatiaoyu;
public class Thread_Test6 {
public static void main(String[] args) throws Exception {
for(int i=0;i<100;i++) {
System.out.println(Thread.currentThread().getName()+",i="+i);
Thread.sleep(1000);
}
}
}
打印结果:
二、
/*
- 多线程优先级
*/
package com.fatiaoyu;
public class ThreadSetPriority {
public static void main(String[] args) {
Thread.currentThread().setPriority(10);
MyThread7 mt = new MyThread7();
Thread thread = new Thread(mt);
thread.setPriority(1);
thread.setName("优先级低的线程");
thread.start();
for (int i = 0; i < 100; i++) {
System.out.println(Thread.currentThread().getName() + ",i=" + i);
}
}
}
class MyThread7 implements Runnable {
public void run() {
for (int i = 0; i < 100; i++) {
System.out.println(Thread.currentThread().getName() + ",i=" + i);
}
}
}
打印结果: