// -Xmx512m -Xms512m
@Slf4j
@RestController
public class AddStringController {
@GetMapping("/add-string/run")
public void run(@RequestParam final Integer millis) throws InterruptedException {
final Thread thread = new Thread(new AddStringRunnable());
thread.start();
Thread.sleep(millis);
thread.interrupt();
}
public static class AddStringRunnable implements Runnable {
private final List<String> list = new ArrayList<>();
public void run() {
log.info("### AddString start");
final byte[] array = new byte[7];
try {
while (true) {
new Random().nextBytes(array);
list.add(new String(array, StandardCharsets.UTF_8));
Thread.sleep(0);
}
} catch (final InterruptedException e) {
log.info("### AddString interrupt");
}
}
}
}