Thread.sleep(100);하면 무조~건 100ms동안 (약간의 오차) 정지되는게 "보장" 되는줄알았어요.
package test;
import java.util.LinkedList;
import java.util.List;
public class Test
{
public static void main(String[] args)
{
Thread th = new Thread(()->
{
List<String> list = new LinkedList<>();
for(int i = 0 ; i < 100000000 ; i++)
list.add("apple");
});
th.start();
Thread th2 = new Thread(()->
{
List<String> list = new LinkedList<>();
while(true)
{
try
{
Thread.sleep(100);
System.out.println("0.1초마다 실행중임");
} catch (InterruptedException e)
{
}
}
});
th2.start();
}
}
아예 1.5초이상 정지 되기도 하고 2초를 넘기기도 하고..
그러다 갑자기 0.1초 동안 잘 정지되기도 하고..
이유는 짐작이 가지만, 뭔가 진리처럼 알고있던게 깨져서 쇼킹하네요잉