标题:java学习之疑——线程
取消只看楼主
Sieben7
Rank: 2
等 级:论坛游民
帖 子:116
专家分:20
注 册:2007-4-16
 问题点数:0 回复次数:0 
java学习之疑——线程
class XThread extends Thread{
long count;
XThread(String name){
super(name);
}
public void run(){
for(int i=1;i<=5;i++){
for(int j=1;j<=10000;j++){
count+=1;
}
try{
Thread.sleep(1000);
}
catch(Exception e){
}
}
}
}
public class Application{
public static void main(String[] args){
XThread highPriorityThreadObj=new XThread(">>>Thread对象");
XThread lowPriorityThreadObj=new XThread("<<<Thread对象");
highPriorityThreadObj.setPriority(Thread.NORM_PRIORITY+1);
lowPriorityThreadObj.setPriority(Thread.NORM_PRIORITY-1);

lowPriorityThreadObj.start();
highPriorityThreadObj.start();

try{
Thread.sleep(1000);
}
catch(Exception e){
}
System.out.println("highPriorityThreadObj的count值是"+highPriorityThreadObj.count);
System.out.println("lowPriorityThreadObj的count值是"+lowPriorityThreadObj.count);
System.out.println("highPriorityThreadObj is alive?"+highPriorityThreadObj.isAlive());
System.out.println("lowPriorityThreadObj is alive?"+lowPriorityThreadObj.isAlive());
}
}

Z:\>javac Application.java

Z:\>java Application
highPriorityThreadObj的count值是20000
lowPriorityThreadObj的count值是10000
highPriorityThreadObj is alive?true
lowPriorityThreadObj is alive?true

为什么会出现20000和10000啊?我是java小白,希望路过的大牛们能点播一二o(∩_∩)o...

搜索更多相关主题的帖子: java 线程 学习 
2007-05-10 08:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-138106-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.091847 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved