zoukankan      html  css  js  c++  java
  • JavaSE 基础 第56节 多线程应用

    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();//就绪状态
        }
    
    }
  • 相关阅读:
    各种插件
    如何在C#中选择正确的集合 转
    转载 hashtable和dictionary的区别
    堆和栈的区别 转载
    数据结构王道错题集2019版(上>一>四章)
    mongoDB连接数据库
    linuix没有网络
    rand函数
    mongodb学习(入门。。。。。)
    先随便写
  • 原文地址:https://www.cnblogs.com/cenliang/p/5634267.html
Copyright © 2011-2022 走看看