publicstaticfinalint | MAX_PRIORITY | 10 |
publicstaticfinalint
MIN_PRIORITY
1
<!-- -->
publicstaticfinalint
NORM_PRIORITY
5
- /**
- *@(#)TestPriority.java
- *
- *
- *@author
- *@version1.002008/10/10
- */
- publicclassTestPriority{
- publicTestPriority(){
- }
- publicstaticvoidmain(String[]args)
- {
- T1t1=newT1();
- T2t2=newT2();
- t1.setPriority(NORM_PRIORITY+3);
- t2.start();t1.start();
- }
- }
- classT2extendsThread
- {
- publicvoidrun()
- {
- for(inti=0;i<1000;i++)
- System.out.println("-----t2"+i);
- }
- }
- classT1extendsThread
- {
- publicvoidrun()
- {
- for(inti=0;i<1000;i++)
- System.out.println("t1"+i);
- }
- }
本文提供了一个Java示例程序,展示了如何通过设置不同优先级的线程来观察其执行顺序的变化。程序创建了两个继承自Thread类的子线程T1和T2,并为其中一个线程设置了高于默认的优先级。
665

被折叠的 条评论
为什么被折叠?



