
Thread::start() 메서드는 스레드가 실행되기 전에 호출되는 메서드는 없으며, 스레드가 이미 실행중인 상태에서 다시 호출되는 경우 스레드는 다시 시작되지 않고, 무시됩니다.
스레드가 실행중인 상태에서 다시 호출되는 경우, 스레드의 상태는 RUNNABLE에서 RUNNING으로 변경되지 않으며, 스레드가 이미 실행중인 상태이기 때문에 다시 시작되지 않습니다.
이러한 동작은 Java의 스레드 API의 규칙에 따라서 동작합니다.
스레드가 실행중인 상태에서 다시 호출되는 경우, 다음의 예제를 통해 확인할 수 있습니다.
#hostingforum.kr
java
public class Main {
public static void main(String[] args) {
Thread thread = new Thread(() -> {
while (true) {
System.out.println("스레드가 실행중입니다.");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
thread.start();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
thread.start();
}
}
위의 예제를 실행하면, 스레드가 이미 실행중인 상태에서 다시 호출되었을 때, 스레드는 다시 시작되지 않고, 무시됩니다.
2025-06-22 04:06