public void fun(int threadCount) {//here, argument threadCount is 2
while(threadCount-->0)
new Thread() {
public void run() {
while(true) {
this.sleep(3000);
System.out.println("");
}
}
}
}
while(threadCount-->0)
new Thread() {
public void run() {
while(true) {
this.sleep(3000);
System.out.println("");
}
}
}
}
到底在类B里实现类A呢,还是类A,类B各有一个线程呢,@#$%^&*()
import java.lang.Thread;public class test{
public static void main(String[] args) throws Exception{
new B().run();
}
};class B extends Thread{
private String flag ;
B(){}
B(String flag){
this.flag = flag;
}
public void run(){
try{
new A("1").start();
this.sleep(3000);
new A("2").start();
}catch(Exception e){
}
}
};class A extends Thread{
private String flag ;
A(String flag){
this.flag = flag;
}
public void run(){
while(1==1){
try{
this.sleep(6000);
System.out.println(flag);
}catch(Exception e){
}
}
}};
不知这样行不??