1继承thread public class MultiThread1 extends Thread{ public void run(){ for(int i=0; i<7; i++){ System.out.println("name:"+this.getName()+" i:"+ i+" "); } } public static void main(String[] args) { MultiThread1 tA = new M…
回顾: 接上篇博客 java线程--三种创建线程的方式,这篇博客主要介绍第三种方式Callable和Future.比较继承Thread类和实现Runnable接口,接口更加灵活,使用更广泛.但这两种方式都没有返回值,要想返回相应的数据,就要使用Callable和Future方式. 基础: 1.Callable 还是从定义开始,Callable接口有返回值,并且可以抛出异常. /**(有返回值的任务,可能抛出异常) * A task that returns a result and may th…
回顾: 接上篇博客 java线程--三种创建线程的方式,这篇博客主要介绍第三种方式Callable和Future.比较继承Thread类和实现Runnable接口,接口更加灵活,使用更广泛.但这两种方式都没有返回值,要想返回相应的数据,就要使用Callable和Future方式. 基础: 1.Callable 还是从定义开始,Callable接口有返回值,并且可以抛出异常. /**(有返回值的任务,可能抛出异常) * A task that returns a result and may th…