|
@ -2,6 +2,8 @@ package com.ai.ipu.server.control;
|
2
|
2
|
|
3
|
3
|
import java.util.concurrent.atomic.AtomicInteger;
|
4
|
4
|
|
|
5
|
import org.slf4j.Logger;
|
|
6
|
import org.slf4j.LoggerFactory;
|
5
|
7
|
import org.springframework.stereotype.Controller;
|
6
|
8
|
import org.springframework.web.bind.annotation.RequestMapping;
|
7
|
9
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
@ -9,6 +11,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
9
|
11
|
@Controller
|
10
|
12
|
@RequestMapping("/graceful")
|
11
|
13
|
public class GracefulTestController {
|
|
14
|
private static final Logger logger = LoggerFactory.getLogger(GracefulTestController.class);
|
12
|
15
|
// 计数器
|
13
|
16
|
public AtomicInteger started = new AtomicInteger();
|
14
|
17
|
public AtomicInteger ended = new AtomicInteger();
|
|
@ -17,14 +20,14 @@ public class GracefulTestController {
|
17
|
20
|
@ResponseBody
|
18
|
21
|
public String hello() {
|
19
|
22
|
|
20
|
|
System.out.println(Thread.currentThread().getName() + " -> " + this + " Get one, got: " + started.addAndGet(1));
|
|
23
|
logger.debug(Thread.currentThread().getName() + " -> " + this + " Get one, got: " + started.addAndGet(1));
|
21
|
24
|
try {
|
22
|
25
|
Thread.sleep(1000 * 100); // 模拟一个执行时间很长的任务
|
23
|
26
|
} catch (InterruptedException e) {
|
24
|
|
e.printStackTrace();
|
|
27
|
logger.info("模拟任务被中断", e);
|
25
|
28
|
}
|
26
|
29
|
|
27
|
|
System.out.println(
|
|
30
|
logger.debug(
|
28
|
31
|
Thread.currentThread().getName() + " -> " + this + " Finish one, finished: " + ended.addAndGet(1));
|
29
|
32
|
return "hello";
|
30
|
33
|
}
|