[求助] 急!急!急!请教一个线程的问题
我的源程序如下:import *;
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 static context
new PrTest(2,i).start();
^
1 error
请问这是什么原因?
高手帮忙了,