博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JAVA线程优先级
阅读量:4606 次
发布时间:2019-06-09

本文共 1339 字,大约阅读时间需要 4 分钟。

可以用setPriority来设置线程的优先级,getPriority取得线程的优先级:

1 package priority; 2  3 import sharevar.Machine; 4  5 public class priority extends Thread { 6     private static StringBuffer log=new StringBuffer(); 7     private static int count=0; 8      9     public void run() {10         for (int a=0;a<20;a++) {11             log.append(currentThread().getName()+":"+a);12             if (++count %10==0) log.append("\n");13         }14     }15 16     /**17      * @param args18      */19     public static void main(String[] args) {20         // TODO Auto-generated method stub21         Machine m1=new Machine();22         Machine m2=new Machine();23         m1.setName("m1");24         m2.setName("m2");25         26         Thread main=Thread.currentThread();   //获得主线程27         //查看和设置线程的优先级28         System.out.println("default priority of main:"+main.getPriority());29         //打印m2线程默认优先级30         System.out.println("default priority of m1:"+m1.getPriority());31         //打印m2线程默认优先级32         System.out.println("default priority of m2:"+m2.getPriority());33         34         m2.setPriority(Thread.MAX_PRIORITY);35         m1.setPriority(Thread.MIN_PRIORITY);36         37         m1.start();38         m2.start();39         System.out.println(log);40     }41 42 }

 

转载于:https://www.cnblogs.com/djcsch2001/archive/2012/05/06/2486622.html

你可能感兴趣的文章
基于空间直方图meanshift跟踪
查看>>
linux+apache+mysql+php平台构建及环境配置
查看>>
MySQl Study学习之--MySQl二进制日志管理
查看>>
四种会话跟踪技术
查看>>
【转】C++之父 Bjarne Stroustrup访谈录
查看>>
nodeJS项目gitignore文件参考
查看>>
iTOP4418开发板Android4.4/5.1.1_Linux3.4.39_QT5.7_Ubuntu12.04系统
查看>>
3ds max学习笔记-- 复合对象运算
查看>>
Handler 的sendEmptyMessage(int what)和sendMessage(Message msg)有啥区别?
查看>>
ubuntu下screen的使用
查看>>
SQL中# 与$ 的区别
查看>>
逻辑卷LVM
查看>>
linux基础-CentOS下安装JDK的三种方法
查看>>
springMVC绑定json参数之二(2.1)
查看>>
display的32种写法--摘抄
查看>>
H5学习第四周
查看>>
AJAX无刷新加购物车
查看>>
【bzoj5174】[Jsoi2013]哈利波特与死亡圣器 二分+树形dp
查看>>
Cloud Test 单页面即时监测功能上线!
查看>>
Allowed memory size of 134217728 bytes exhausted (tried to allocate 2 bytes)
查看>>