4月15日,TestPriority,每日20行。

来源:互联网 发布:ipad做笔记软件 编辑:程序博客网 时间:2024/05/20 06:23
class Resource implements Runnable {    volatile public int i;    public Resource(int _i){        i = _i;    }    public void run(){        while(true){            if(i > 0){                i--;                System.out.println(Thread.currentThread().getName() + " " + i);            }            else{                System.out.println(Thread.currentThread().getName());                break;            }        }    }}public class TestPriority {    public static void main(String[] args) {        Resource m = new Resource(100);        Thread t1 = new Thread(m);        Thread t2 = new Thread(m);        t2.setPriority(Thread.MAX_PRIORITY);        t1.start();        try{            Thread.sleep(5);        }        catch(Exception e){}        t2.start();    }}

这里写图片描述

0 0
原创粉丝点击