1、AdminController
package com.controller;
import com.myThread.AdminThread;
import com.myThread.MyRunnable;
import org.springframework.web.bind.annotation.*;
@RestController
@CrossOrigin
@RequestMapping("/admin")
public class AdminController{
@GetMapping("/{id}")
public long findById(@PathVariable Long id){
return id;
}
@GetMapping("dade01/{id}")
public long dade01(@PathVariable Long id){
//创建了一个参数对象
MyRunnable my = new MyRunnable();
//创建1个线程,并把参数传递给这个线程
Thread t1 = new Thread(my);
t1.start();
return 33;
}
}
2.MyRunnable
package com.myThread;
public class MyRunnable implements Runnable{
@Override
public void run() {
//线程启动后执行的代码
for (int i = 0; i < 100; i++) {
System.out.print("线程"+i+"\n");
}
}
}