package com.controller;import com.myThread.AdminThread;import com.myThread.MyCallable;import com.myThread.MyRunnable;import org.springframework.web.bind.annotation.*;import java.util.concurrent.*;
//上面引入*,所以这个可以注销
//import java.util.concurrent.ConcurrentHashMap;
@RestController
@CrossOrigin
@RequestMapping("/admin")
public class AdminController{
@GetMapping("/{id}")
public long findById(@PathVariable Long id) throws InterruptedException {
ConcurrentHashMap<String,String> maps = new ConcurrentHashMap<>();
Thread ti = new Thread(() ->{for(int i =0; i <10; i++){
maps.put(i+"",i+"laila");}});
ti.start();
//加一下延迟,等线程把数据写入,不然是null
Thread.sleep(1000);for(int i =0; i <10; i++){
System.out.print(maps.get(i+"")+"\n");}returnid;}}