多线程测试

public class ThreadTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Thread ra1=new ThreadA();//利用多态实例化一个ThreadA对象
		Runnable ra2=new ThreadB();//利用多态实例化一个ThreadB对象
		
		Thread t1=new Thread(ra1);//就像一层包装,把ra1给包装一下
		Thread t2=new Thread(ra2);
		
		t1.start();
		t2.start();
		
	}

}
/*线程A继承Thread类*/
class ThreadA extends Thread {
	public void run(){
		for(int i=0;i<10;i++){
			System.out.println(i + "¥");
			
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
/*线程B继承Runnable接口*/
class ThreadB implements Runnable{
	public void run(){
		for(int i=0;i<10;i++){
			System.out.println(i + "$");
			
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}

多线程测试,布布扣,bubuko.com

多线程测试

上一篇:Java NIO小结


下一篇:Prometheus+Alertmanager配置邮件报警