1.继承Thread类
class PrimeThread extends Thread { long minPrime; PrimeThread(long minPrime) { this.minPrime = minPrime; } public void run() { // compute primes larger than minPrime . . . } }
然后启动如下
PrimeThread p = new PrimeThread(143); p.start();
2.实现Runable方法
class PrimeRun implements Runnable { long minPrime; PrimeRun(long minPrime) { this.minPrime = minPrime; } public void run() { // compute primes larger than minPrime . . . } }
然后启动稍微有一些不同
PrimeRun p = new PrimeRun(143); new Thread(p).start();
原文:https://www.cnblogs.com/nihaoya-czw/p/10352283.html