| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 603 人关注过本帖
标题:求教!!!线程优先级的问题
只看楼主 加入收藏
netfan
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2005-8-15
收藏
 问题点数:0 回复次数:0 
求教!!!线程优先级的问题

我的程序如下: import java.io.*; public class PriorityTest { static int numthreads=4; static boolean yield=true; static int counter[]=new int[numthreads]; static PrintWriter out =new PrintWriter(System.out,true); public static void main(String[] args) { int numIntervals=10; if (args.length>0) { yield=false; } out.println("Using yield()?"+(yield ? "Yes" : "No")); for(int i=0;i<numthreads;i++) {

(new PrTest(((i>1)?4 :(i+1)),i)).start(); } // ThreadInfo.printAllThreadInfo(); out.println(); int step=0; while(true) { boolean alldown=true; try { Thread.sleep(300);

} catch (InterruptedException e) { } out.print("step "+(step++)+": COUNTERS: "); for( int j=0;j<numthreads;j++) { out.print(" "+counter[j]); if (counter[j]<2000000) { alldown=false; } } out.println(); if (alldown) { break; } System.exit(0); } }

class PrTest extends Thread { int id; PrTest(int priority,int id) { super("PrTestThread#"+id); this.id=id; setPriority(priority); } public void run() { for (int i=0;i<=2000000 ;i++ ) { if ((i % 3000)==0 && PriorityTest.yield) { yield(); } PriorityTest.counter[i]=i; } } } } 变异实提示错误: PriorityTest.java:21: non-static variable this cannot be referenced from a stati c context new PrTest(((i>1)?4 :(i+1)),i).start(); ^ 1 error 请问只是什么原因?? 高手帮忙了

搜索更多相关主题的帖子: 线程 
2005-09-14 16:59
快速回复:求教!!!线程优先级的问题
数据加载中...
 
   



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

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