1. 程式人生 > >多執行緒實現Runnable介面

多執行緒實現Runnable介面

package com.lxxu.testthread;

class MyThread2 implements Runnable{//執行緒的主體類
	private String title;
	public MyThread2(String title){
		this.title = title;
	}
	
	@Override
		public void run(){//執行緒的主體方法
			for(int i = 0; i < 10; i++){
				System.out.println(this.title+"執行,i="+i);
			}
		}
}

public class ThreadDemo2{
	public static void main(String[] args)
	{
		Thread threadA = new Thread(new MyThread2("執行緒A"));
		Thread threadB = new Thread(new MyThread2("執行緒B"));
		Thread threadC = new Thread(new MyThread2("執行緒C"));
		
		threadA.start();
		threadB.start();
		threadC.start();
	}
}