给你个线成的例子(可以正常运行),你看看吧
public class SimpleThread extends Thread{
static int tn = 0;
int count = 5;
int tnumber = ++tn;
SimpleThread(){
System.out.println("making " + tnumber);
}
public void run(){
while(true)
{
System.out.println("Thread" + tnumber + "(" + count+ ")");
if (--count == 0) return;
}
}
public static void main(String[] args){
for (int i = 0;i<5;i++){
new SimpleThread().start();
}
System.out.println("main");
}
}
public class SimpleThread extends Thread{
static int tn = 0;
int count = 5;
int tnumber = ++tn;
SimpleThread(){
System.out.println("making " + tnumber);
}
public void run(){
while(true)
{
System.out.println("Thread" + tnumber + "(" + count+ ")");
if (--count == 0) return;
}
}
public static void main(String[] args){
for (int i = 0;i<5;i++){
new SimpleThread().start();
}
System.out.println("main");
}
}
A.member=0;
或者在申明时初始化之——
class A
{
static int member=0;
}