主方法 MainTest.java
            
            
              java
              
              
            
          
          package com.example.mythread;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
public class MainTest {
    public static void main(String[] data){
//        以下的方法的线程并发执行
        //执行线程一
        ExtendsThread extendsThread = new ExtendsThread();
        // 1.执行线程中的方法
        extendsThread.getData();
        // 2. 或者 启动线程
        extendsThread.start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        //执行线程二
        Runnable runnable = new RunnableThread();
        Thread thread2 = new Thread(runnable);
        //1 启动线程
        thread2.start();
        //执行线程三 实现Callable接口和Future创建线程
        Callable<String> callable = new CallableThread();
        FutureTask<String> futureTask = new FutureTask<>(callable);
        Thread thread3 = new Thread(futureTask);
        thread3.start();
        try {
            //获取线程返回值
            System.out.println(futureTask.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        // Lambda表达式简化写法
        //扩展 函数式接口 创建线程
        Thread thread4 = new Thread(() ->{
            System.out.println("扩展函数式接口的输出");
        });
        thread4.start();
        //扩展 Runnable函数式接口 创建线程
        Runnable runnable2 =()->{
            System.out.println("扩展Runnable函数式接口的输出");
        };
        new Thread(runnable2).start();
        // 扩展 Callable 函数式接口
        Callable<String> c = () ->{
            System.out.println("扩展线程开始运行");
            //线程暂停3秒 表示业务处理啥的
            Thread.sleep(3000);
            System.out.println("扩展线程执行完成");
            return "Callable接口实现返回的字符串";
        };
        //启动线程
        //new Thread(new FutureTask<String>(c)).start();
        FutureTask<String> futureTask2 = new FutureTask<String>(c);
        new Thread(futureTask2).start();
        try {
            //输出返回数据
            System.out.println(futureTask2.get());
        } catch (Throwable e) {
            e.printStackTrace();
        }
        //
        new Thread(){
            @Override
            public void run() {
                super.run();
                System.out.println("线程中的输出");
            }
        }.start();
    }
}方式一:写个类继承Thread ExtendsThread.java
            
            
              java
              
              
            
          
          package com.example.mythread;
// 方式一 写个类 extends Thread
public class ExtendsThread extends Thread{
    @Override
    public void run() {
        super.run();
        //调用方法
        getData();
    }
    public void getData(){
        System.out.println("方式一:我是线程中的输出");
    }
}方式二: 写个类实现 Runnable接口 RunnableThread.java
            
            
              java
              
              
            
          
          package com.example.mythread;
//创建线程方式二 实现 Runnable  接口
public class RunnableThread implements Runnable{
    @Override
    public void run() {
        //调用方法
        getData();
    }
    public void getData(){
        System.out.println("方式二:我是线程中的输出");
    }
}方式三 写个类实现Callable接口和Future创建线程 CallableThread.java
            
            
              java
              
              
            
          
          package com.example.mythread;
import java.util.concurrent.Callable;
// 方式三 实现Callable接口和Future创建线程
public class CallableThread implements Callable<String> {
    @Override
    public String call() throws Exception {
        getData();
        return "要返回的数据";
    }
    public void getData(){
        System.out.println("方式三:我是线程中的输出");
    }
}