黑马程序员技术交流社区
标题:
线程5
[打印本页]
作者:
宁少
时间:
2015-11-5 00:25
标题:
线程5
/**
* 实现Runnable接口的类
*
* @author leizhimin 2008-9-13 18:12:10
*/
public
class
DoSomething
implements
Runnable {
private
String name;
public
DoSomething(String name) {
this
.name = name;
}
public
void
run() {
for
(
int
i = 0; i < 5; i++) {
for
(
long
k = 0; k < 100000000; k++) ;
System.out.println(name +
": "
+ i);
}
}
}
/**
* 测试Runnable类实现的多线程程序
*
* @author leizhimin 2008-9-13 18:15:02
*/
public
class
TestRunnable {
public
static
void
main(String[] args) {
DoSomething ds1 =
new
DoSomething(
"阿三"
);
DoSomething ds2 =
new
DoSomething(
"李四"
);
Thread t1 =
new
Thread(ds1);
Thread t2 =
new
Thread(ds2);
t1.start();
t2.start();
}
}
作者:
我若为神
时间:
2015-11-5 00:41
666666666666666666
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2