线程的优先权
来源:互联网 发布:applem2引擎全套源码 编辑:程序博客网 时间:2024/04/27 21:36
import java.awt.BorderLayout;import java.awt.Container;import javax.swing.JFrame;import javax.swing.JProgressBar;public class Jointest extends JFrame{/** * */private static final long serialVersionUID = 1L;private Thread threadA;private Thread threadB;final JProgressBar progressBar=new JProgressBar();final JProgressBar progressBar2=new JProgressBar();int count=0;public static void main(String[] args){init(new Jointest(),100,100);}public Jointest(){super();Container c=getContentPane();//添加两个进度条c.add(progressBar,BorderLayout.NORTH);c.add(progressBar2,BorderLayout.SOUTH);//设置进度条显示数字progressBar.setStringPainted(true);progressBar2.setStringPainted(true); threadA=new Thread(new Runnable(){int count=0;public void run(){while(true){progressBar.setValue(++count);try{Thread.sleep(100);threadB.join(); //线程的加入}catch(Exception e){e.getStackTrace();}}}});threadA.start();threadB=new Thread(new Runnable(){int count=0;public void run(){while(true){progressBar2.setValue(++count);try{Thread.sleep(100);}catch(Exception e1){e1.printStackTrace();}if(count==100)break;}}});threadB.start();}public static void init(JFrame frame,int width,int heigth){frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(width,heigth);frame.setVisible(true);}}
下面是关于是线程的优先权的设置
import java.awt.GridLayout;import javax.swing.JFrame;import javax.swing.JProgressBar;public class PriorityTest extends JFrame{/** * */private static final long serialVersionUID = -7759161002167557345L;private Thread threadA;private Thread threadB;private Thread threadC;private Thread threadD;final JProgressBar progressBarA=new JProgressBar();final JProgressBar progressBarB=new JProgressBar();final JProgressBar progressBarC=new JProgressBar();final JProgressBar progressBarD=new JProgressBar();@SuppressWarnings("unused")private int count=0;public PriorityTest(){super();getContentPane().setLayout(new GridLayout(4,1,20,20));getContentPane().add(progressBarA);getContentPane().add(progressBarB);getContentPane().add(progressBarC);getContentPane().add(progressBarD);progressBarA.setStringPainted(true);progressBarB.setStringPainted(true);progressBarC.setStringPainted(true);progressBarD.setStringPainted(true);threadA=new Thread(new MyThread(progressBarA));threadB=new Thread(new MyThread(progressBarB));threadC=new Thread(new MyThread(progressBarC));threadD=new Thread(new MyThread(progressBarD));setPriority("threadA",10,threadA);setPriority("threadB",5,threadB);setPriority("threadC",4,threadC);setPriority("threadD",1,threadD);}public static void setPriority(String threadName,int priority,Thread t){t.setPriority(priority); //设置线程的进程优先权,最大值为10,最小值为1t.setName(threadName); //main中优先权为5t.start();}public static void main(String[] args){init(new PriorityTest(),100,100);}public static void init(JFrame frame,int width,int height){frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(500,600);frame.setVisible(true);}private final class MyThread implements Runnable{private final JProgressBar bar;int count=0;private MyThread(JProgressBar bar){this.bar=bar;}public void run(){while(true){bar.setValue(count+=1);try{Thread.sleep(1000);}catch(Exception e){System.out.println("当前线程被中断");}}}}}
0 0
- 线程的优先权
- 线程的“优先权”(priority)介绍
- 线程优先权问题
- Win32线程——优先权
- 详解CSS的优先权
- CSS的优先权
- 优先权队列的实现
- python的优先权队列
- [转]详解CSS的优先权
- 正则表达式的优先权顺序
- Flex的事件-- 事件的优先权
- CSS的优先权CSS的执行顺序
- CSS执行顺序与优先权的问题
- Unix 系统的优先数和优先权
- 基于优先权的时间片轮转算法
- OS 使用动态优先权的进程调度
- 【Win32多线程】如何初始化一个新线程,停止一个执行中的线程,调整线程优先权?
- 使用动态优先权的进程调度算法的模拟
- mac chrome 提示 adobe flash player 过期
- 开发环境配置
- 进程优先级
- GDOI2017总结
- 关于利用position定位在页面正中心的问题(还有一个z-index的知识点)
- 线程的优先权
- PortraitPro 15.7.3 标准版 简体中文汉化 自适应简/繁 Windows 系统
- jquery selector基础
- 泛型入门
- typedef和define作用域的问题
- CocosCreator学习6:碰撞系统
- JavaWeb学习三(细解Servlet和ServletContext)
- Android Studio使用Button等控件的英文内容字符串默认大写
- 畅想网站实名制