[线程]——线程基本信息.优先级
来源:互联网 发布:java 怎么用md5 编辑:程序博客网 时间:2024/04/30 05:12
public class MyThread implements Runnable{private boolean flag=true;private int num=0;@Overridepublic void run() {while(flag){System.out.println(Thread.currentThread().getName()+"-->"+num++);}}public void stop(){this.flag=!this.flag;}}
/** * Thread.currentThread() :当前线程 * setName():设置名称 getName():获取名称 isAlive():判断状态 * @author Administrator * */public class InfoDemo01 {/** * @param args * @throws InterruptedException */public static void main(String[] args) throws InterruptedException {MyThread it =new MyThread();Thread proxy =new Thread(it,"挨踢");//proxy.setName("test");System.out.println(proxy.getName());System.out.println(Thread.currentThread().getName()); //mainproxy.start();System.out.println("启动后的状态:"+proxy.isAlive());Thread.sleep(200);it.stop();Thread.sleep(100);System.out.println("停止后的状态:"+proxy.isAlive());}}
/** * 优先级:概率,不是绝对的先后顺序 MAX_PRIORITY 10 NORM_PRIORITY 5 (默认) MIN_PRIORITY 1 setPriority() getPriority() * @author Administrator * */public class InfoDemo2 {/** * @param args * @throws InterruptedException */public static void main(String[] args) throws InterruptedException {MyThread it =new MyThread();Thread p1 =new Thread(it,"挨踢1");MyThread it2 =new MyThread();Thread p2 =new Thread(it2,"挨踢2");p1.setPriority(Thread.MIN_PRIORITY); //设置优先级p2.setPriority(Thread.MAX_PRIORITY);//设置优先级p1.start();p2.start();Thread.sleep(100);it.stop();it2.stop();}}
0 0
- [线程]——线程基本信息.优先级
- 线程第八课,线程的基本信息,优先级
- 线程基本信息
- 学习笔记——JAVA线程<3>线程的基本信息
- 线程调度—优先级调度
- Java 线程的基本信息
- Java中的线程基本信息
- C++进阶—>线程优先级与线程安全
- java线程——中断线程+线程状态+线程属性(优先级)
- 线程优先级
- 线程优先级
- 线程优先级
- 线程优先级
- 线程优先级
- 线程优先级
- 线程优先级
- 线程优先级
- 线程优先级
- Linux jar包 后台运行
- word中如何在方框中打钩
- 陈一舟:每个人风口来的时间不一样
- 5-CSS-浮动清除-继承-优先级-定位-引入CSS-盒子模型
- C语言str函数系列
- [线程]——线程基本信息.优先级
- ng-bind
- Android选择通讯录姓名和手机号信息
- 014.php分支语句switch
- [架构]我眼中的Android架构
- 2017
- ng-cloak
- 1090. Highest Price in Supply Chain (25)
- 选择,循环,顺序结构