package com.springboot.hello.timeout;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WaitTimeoutTest {
private static final Logger logger = LoggerFactory.getLogger(WaitTimeoutTest.class);
private static volatile int num = 0;
@Test
public void testTimeout() {
System.out.println(waitTime(100));
}
public int waitTime(long time) {
long future = System.currentTimeMillis() + time;
long remaining = time;
while (num < 10 && remaining > 0) {
num++;
remaining = future - System.currentTimeMillis();
logger.info("WaitTimeoutTest.waitTime start, remaining : [{}],num : [{}]", remaining, num);
}
return num;
}
}