package com.example.demo.controller; import com.example.demo.tool.Task; import com.example.demo.tool.TaskRunnable; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * 多线程 */ @RestController @RequestMapping("/") public class ThreadController { @GetMapping("/thread") public void threadDemo(){ Task thread1 = new Task(); Task thread2 = new Task(); Task thread3 = new Task(); thread1.setName("task1"); thread2.setName("task2"); thread3.setName("task3"); thread1.start(); thread2.start(); thread3.start(); } @GetMapping("/runnable") public void runnableDemo(){ TaskRunnable taskRunnable = new TaskRunnable(); Thread thread1 = new Thread(taskRunnable,"task1"); Thread thread2 = new Thread(taskRunnable,"task2"); Thread thread3 = new Thread(taskRunnable,"task3"); thread1.start(); thread2.start(); thread3.start(); } }