java多线程设置优先级
来源:互联网 发布:淘宝网发货地址怎么改 编辑:程序博客网 时间:2024/05/16 11:37
package com.itbuluoge.mythread;class SimpleThread extends Thread{private int priority;public SimpleThread(int i){priority=i;}public void run(){Thread.currentThread().setPriority(priority);for(int i=0;i<10000;i++){try {Thread.sleep(100);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}System.out.println(priority);}}}public class PriorityDemo {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubSimpleThread high=new SimpleThread(Thread.MAX_PRIORITY);SimpleThread low=new SimpleThread(Thread.MIN_PRIORITY);high.start();low.start();}}
如上述代码所示,运行的两个线程,分别设置最高和最低的优先级,我们可以看看输出结果:
10
1
10
1
10
1
10
1
10
1
10
1
10
1
10
1
1
10
1
10
10
1
10
1
1
可以初步发现,优先级高的,得到的调度会更优先一些,但是也不是非常明显。
0 0
- java多线程设置优先级
- Java多线程优先级设置
- linux设置多线程优先级
- Java程序中多线程的优先级设置方法
- JAVA多线程Thread setPriority 设置线程优先级方法入门详解
- java多线程-线程优先级
- Java 多线程优先级
- java 多线程的优先级
- java 多线程优先级 测试
- java多线程-线程优先级
- java多线程--优先级
- Java多线程优先级
- Java 多线程:线程优先级
- Java多线程优先级
- Java多线程--线程优先级
- 【多线程】线程的优先级设置
- java线程优先级设置
- Java多线程调度—优先级
- C语言函数---G
- 求二叉树的镜像
- Android刷新系统图册
- 常见经典排序算法
- Cts框架解析(4)-任务的添加
- java多线程设置优先级
- 在ubuntukylin下安装chrome浏览器
- 井冈山和梁山的异同
- 拿下内推(1):了解内推要求
- 《黑马》学习笔记
- 为什么会出现Notice: Undefined index: submit in D:\xampp\htdocs\test.php on line 19
- 2-1 水仙花数
- android自定义AlertDialog
- iOS_动态插入删除行