-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThreadPinningController.java
42 lines (35 loc) · 1.28 KB
/
ThreadPinningController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.mikemybytes.jfr.pinning;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.Duration;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
@RestController
@RequestMapping("/pinning")
class ThreadPinningController {
private static final Logger log = LoggerFactory.getLogger(ThreadPinningController.class);
@PostMapping
void pinCarrierThread() throws InterruptedException {
var cdl = new CountDownLatch(1);
Thread.ofVirtual()
.name("web-vt-" + UUID.randomUUID())
.start(() -> {
synchronized (this) {
log.info("Causing thread pinning for example purposes");
sleep(Duration.ofMillis(250));
}
cdl.countDown();
});
cdl.await();
}
private void sleep(Duration duration) {
try {
Thread.sleep(duration.toMillis());
} catch (InterruptedException e) {
throw new IllegalStateException("Unexpected InterruptedException", e);
}
}
}