当前位置: 代码迷 >> Java相关 >> 求教!!!线程优先级的问题
  详细解决方案

求教!!!线程优先级的问题

热度:113   发布时间:2005-09-14 16:59:00.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 请问只是什么原因?? 高手帮忙了

搜索更多相关的解决方案: 线程  

----------------解决方案--------------------------------------------------------
  相关解决方案