| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 589 人关注过本帖
标题:[求助] 急!急!急!请教一个线程的问题
取消只看楼主 加入收藏
netfan
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2005-8-15
收藏
 问题点数:0 回复次数:0 
[求助] 急!急!急!请教一个线程的问题
我的源程序如下:
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
请问这是什么原因?
高手帮忙了,
搜索更多相关主题的帖子: 线程 
2005-09-15 09:29
快速回复:[求助] 急!急!急!请教一个线程的问题
数据加载中...
 
   



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

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