码迷,mamicode.com
首页 > 编程语言 > 详细

java 第56节 多线程应用

时间:2016-07-01 21:25:52      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

2016-07-01

package com.java1995;

public class MyRunnable1 implements Runnable{

    @Override
    public void run() {
        // TODO Auto-generated method stub
        for(int i=0;i<100;i++){
            System.out.print("+");
        }
        
    }

}

 

package com.java1995;

public class MyRunnable2 implements Runnable{

    @Override
    public void run() {
        // TODO Auto-generated method stub
        for(int i=0;i<100;i++)
            System.out.print("*");
    }

}

 

 

package com.java1995;

public class Test {
    
    public static void main(String[] args) {
        MyRunnable1 r1=new MyRunnable1();
        MyRunnable2 r2=new MyRunnable2();
        
        Thread t1=new Thread(r1);
        Thread t2=new Thread(r2);
        
        System.out.println("t1的优先级:"+ t1.getPriority());
        System.out.println("t2的优先级:"+t2.getPriority());
        
        //给t1设置最高的优先级
        t1.setPriority(Thread.MAX_PRIORITY);
        System.out.println("t1改变之后的优先级是:"+t1.getPriority());
        //给t2设置最低的优先级
        t2.setPriority(Thread.MIN_PRIORITY);
        System.out.println("t2改变之后的优先级是:"+t2.getPriority());

        t1.start();//就绪状态
        t2.start();//就绪状态
    }

}

 

java 第56节 多线程应用

标签:

原文地址:http://www.cnblogs.com/cenliang/p/5634267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!