package songyan;
/*
* 线程组(很少使用):一般线程是由谁创建的就是那个组
* 例:主线程创建t1,t2,那么t1,t2的组就是main
* 组也可以修改,使用ThreadGroup
*
* 优先级(Priority):抢资源的频率
* 线程的优先级:1-10
* t1.setPriority(10);
* 三个常量:
* 1:MIN_PRIORITY
* 10:MAX_PRIORITY
* 5:NORM_PRIORITY
*
* 共享变量用静态
* 固定数据用常量
*
* yield()【用的很少,面试题会出】:强制释放执行权(临时停止)
* 暂停当前执行的线程对象
* 现象:稍微减缓线程的运行,达到所有线程都能执行到的效果
*
*/
class Demo implements Runnable{
public void run()
{
while(true)
{
for( int i=0;i<60;i++)
{
System.out.println(Thread.currentThread().getName()+"***"+i);
Thread.yield();
}
}
}
}
public class test{
public static void main(String[] args) {
Demo d= new Demo();
Thread t1= new Thread(d);
Thread t2 = new Thread(d);
// t1.setPriority(10);
t1.start();
t2.start();
}
}