Java创建线程的两种方式
作者:互联网
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();
标签:PrimeRun,Java,Thread,创建,long,线程,PrimeThread,new,minPrime 来源: https://www.cnblogs.com/nihaoya-czw/p/10352283.html