多线程实现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();
	}
}

猜你喜欢

转载自blog.csdn.net/qq_42740745/article/details/84559891