线程
作者:互联网
package com.yh.thread;
public class RunnableTest {
public static void main(String[] args) {
Runnable r1=new ThreadRunnable1();
Runnable r2=new ThreadRunnable2();
Thread t11=new Thread(r1);
Thread t22=new Thread(r2);
t11.start();
t22.start();
}
}
package com.yh.thread;
public class ThreadRunnable1 implements Runnable{
@Override
public void run() {
for(int i=0;i<1000;i++){
System.out.println("小雨在执行"+i);
}
}
}
package com.yh.thread;
public class ThreadRunnable2 implements Runnable{
@Override
public void run() {
for(int i=0;i<1000;i++){
System.out.println("小雨在执行"+i);
}
}
}
=============================================
package com.yh.thread;
public class ThreadTest {
public static void main(String[] args) {
Thread1 t1=new Thread1();
Thread2 t2=new Thread2();
t1.start();
t2.start();
}
}
package com.yh.thread;
public class Thread2 extends Thread{
public void run(){
for(int i=0;i<1000;i++){
System.out.println("小华在执行"+i);
}
}
}
package com.yh.thread;
public class Thread1 extends Thread{
public void run(){
for(int i=0;i<1000;i++){
System.out.println("小华在执行"+i);
}
}
}
new --start--runnable(可运行状态)--线程调度器--runnning(正在运行状态)--死亡状态
标签:yh,Thread,void,class,线程,new,public 来源: https://www.cnblogs.com/god1/p/12079354.html