标签:long 高级特性 包括 sleep i++ 特性 抽象方法 extend 类继承
| 方法名称 | 说明 |
| Thread(String name) | 创建一个新的Thread对象 |
| Thread(Runnable target) | 根据Runnable对象创建一个线程 |
public class ThreadTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
MyThreadn mt=new MyThreadn();
mt.start();
for(int i=0;i<1000;i++){
System.out.println("main中的run()方法"+i+1);
}
}
}
class MyThreadn extends Thread{
public void run(){
for(int i=0; i<1000;i++){
System.out.println("MyThread中的run()方法"+i+1);
}
}
}
启动钱程时心须调用sar0方法.不能直接调用run0方法,如果直接调用run(方法,虚拟机会认为是在调用类的成员方法,不会创建多线程,
实现Runnable接口创建线程:
public class ThreadTest2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread t=new Thread(new MyThread3());
t.start();
}
}
class MyThread3 implements Runnable{
public void run(){
for(int i=0;i<1000;i++){
System.out.println("好好学习,天天向上"+i);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
标签:long 高级特性 包括 sleep i++ 特性 抽象方法 extend 类继承
原文地址:https://www.cnblogs.com/hurriediy/p/9200730.html