`
1140566087
  • 浏览: 558448 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
博客专栏
2c4ae07c-10c2-3bb0-a106-d91fe0a10f37
c/c++ 入门笔记
浏览量:18509
3161ba8d-c410-3ef9-871c-3e48524c5263
Android 学习笔记
浏览量:313838
Group-logo
J2ME 基础学习课程集
浏览量:18691
A98a97d4-eb03-3faf-af96-c7c28f709feb
Spring 学习过程记录...
浏览量:17550
社区版块
存档分类
最新评论

使用Runnable实现多线程

    博客分类:
  • J2ME
 
阅读更多
import java.util.Date;


//Runnable 接口实现多线程
public class  Thread_RunnableTest implements Runnable {

	private int pauseTime;
	private String Threadname;
	public Thread_RunnableTest(int x,String y){
		this.pauseTime = x;
		this.Threadname = y;
	}

	
	public void run() {
		// TODO Auto-generated method stub
		for(int i=0;i<10;i++){
			try {
				System.out.println(Threadname+":"+new Date(System.currentTimeMillis()));
				Thread.sleep(pauseTime);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		


	}

	//测试线程
	public static void main(String[] args){
		//创建线程 1  
		Thread t1 = new Thread(new Thread_RunnableTest(1000,"我是1线程"));
		t1.start();

		//创建线程 2 
		Thread t2 = new Thread(new Thread_RunnableTest(5000,"我是2线程"));
		t2.start();
	}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics