锁定老帖子 主题:创建线程的方式
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (7)
|
|
---|---|
作者 | 正文 |
发表时间:2009-08-26
There are two ways to create a new thread of execution.
One is to declare a class to be a subclass of class PrimeThread extends Thread { The following code would then create a thread and start it running:
PrimeThread p = new PrimeThread(143); p.start(); The other way to create a thread is to declare a class that implements the
class PrimeRun implements Runnable { long minPrime; PrimeRun(long minPrime) { this.minPrime = minPrime; } public void run() { // compute primes larger than minPrime . . . } } The following code would then create a thread and start it running:
PrimeRun p = new PrimeRun(143); new Thread(p).start();其实,JDK中的Thread也不过是由sun自已实现Runnable接口的类而已. 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 1408 次