好好研究的话,每个版块都够我们好好研究一下的。今天看了一晚上多线程。
附上基本代码,供以后复习回顾
public class TreadTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Demo1 d1 = new Demo1("gao");
Demo1 d2 = new Demo1("wang");
d1.start();
d2.start();
/*Thread d1 = new Thread(new Demo1());
Thread d2 = new Thread(new Demo1());
d1.start();
d2.start();*/
for(int x=0;x<50;x++){
System.out.println("hello"+x);
}
}
}
class Demo1 extends Thread{
//private String name;
Demo1(String name){
//this.name = name;
super(name);
}
public void run(){
for(int x=0;x<40;x++){
System.out.println(this.getName() + "Demo Run" + x);
}
}
}
//实现Runnable接口的方法(建议使用实现接口的方法来定义线程)
/*class Demo1 implements Runnable{
public void run(){
for(int x=0;x<40;x++){
System.out.println("Demo Run" + x);
}
}
}*/ |
|