5.5 用实现Runable的方式定义线程
2011-01-29 11:09
176 查看
p { margin-bottom: 0.21cm; }
定义方式
class
TestThead
implements
Runnable
/*extends
Thread */
{
public
void
run() {
int
index = 0;
while
(
true
)
{
System.
out
.println(
"run()"
+Thread.
currentThread
().getName()+index);
index++;
}
}
}
实例化
使用方式
Thread
testThead =
new
Thread(
new
TestThead());
testThead.start();
定义方式
class
TestThead
implements
Runnable
/*extends
Thread */
{
public
void
run() {
int
index = 0;
while
(
true
)
{
System.
out
.println(
"run()"
+Thread.
currentThread
().getName()+index);
index++;
}
}
}
实例化
使用方式
Thread
testThead =
new
Thread(
new
TestThead());
testThead.start();
相关文章推荐
- 黑马程序员_笔记_多线程(创建线程的第二种方式:实现Runable接口)
- 5.6 实现Runable接口定义线程和直接继承Thead类定义线程的区别
- (总结)线程实现的三种方式(Thread、Runable、Callable)
- JAVA 实现线程的两种方式,举例,详解
- Java基础回顾 : 线程的实现方式
- 线程的实现方式
- JAVA线程系列教程<2>-线程的两种实现方式
- C++实现线程同步的几种方式 线程同步是指同一进程中的多个线程互相协调工作从而达到一致性。之所以需要线程同步,是因为多个线程同时对一个数据对象进行修改操作时,可能会对数据造成破坏,下面是多
- JAVA多线程之——线程的实现方式
- IOS-62-实现进程间、线程间通信的方式
- 线程的实现方式
- 线程 创建和启动线程的两种方式 实现Runnable接口 继承Thread类 重写唯一方法run()
- 用匿名类的方式实现一个线程,并打印
- 4-使用synchronized实现线程间通信-实现线程间通信方式(1)
- 【操作系统】线程间实现同步的方式
- 线程的2种实现方式
- 试解释操作系统原理中的作业,进程,线程,管程各自的定义。进程间的通信如何实现?
- java基础知识回顾之java Thread类--java线程实现常见的两种方式(一)
- JUC-006-创建线程的方式三-实现Callable接口
- JAVA基础再回首(二十四)——多线程的概述、实现方式、线程控制、生命周期、多线程程序练习、安全问题的解决