123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package com.alvin.controller;
- import com.alvin.util.DateUtil;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.concurrent.ConcurrentHashMap;
- @RestController
- @RequestMapping("user")
- public class UserController {
- @GetMapping("age")
- public String test1(Integer age) {
- return age + "!";
- }
- public volatile ConcurrentHashMap<String, String> flags=new ConcurrentHashMap<>();
- @GetMapping("startPrint")
- public String startPrint(String flag) {
- flags.put(flag, flag);
- new Thread(() -> {
- while (flags.contains(flag)) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- System.out.println(flag + DateUtil.getEpochMilli());
- }
- }).start();
- return "1";
- }
- @GetMapping("cancelPrint")
- public String cancelPrint(String flag) {
- flags.remove(flag);
- return "ok";
- }
- }
|