1. 创建和运行线程

具体代码

new Thread(){
    @Override
    public void run() {
        log.debug("running");
    }
}.start();
log.debug("main running");
// 原生方法
Runnable runnable = new Runnable() {
    @Override
    public void run() {
        log.debug("runnable running");
    }
};
new Thread(runnable, "t2").start();
log.debug("main running");

// lambda 表达式
Runnable runnable = () -> log.debug("runnable running");
new Thread(runnable, "t3").start();
log.debug("main running");
FutureTask<Integer> futureTask = new FutureTask<>(
  new Callable<Integer>() {
      @Override
      public Integer call() throws Exception {
          log.debug("hahah");
          return 100;
      }
  }
);
new Thread(futureTask).start();
log.debug("结果是:{}",futureTask.get());

关系

查看进程线程的方法

2. 线程运行原理

栈与栈帧