
Thread::isStarted() 메서드는 Thread가 시작되었는지 여부를 반환합니다.
만약 Thread가 시작되지 않았으면 false를 반환하고, 시작되었다면 true를 반환합니다.
Thread::start() 메서드를 호출한 후 Thread::isStarted() 메서드를 호출했을 때의 결과는 true입니다.
Thread::isStarted() 메서드는 동기화가 필요하지 않습니다.
Thread::isStarted() 메서드의 사용 예시는 다음과 같습니다.
#hostingforum.kr
java
public class Main {
public static void main(String[] args) {
Thread thread = new Thread(() -> {
System.out.println("Thread가 시작되었습니다.");
});
System.out.println("Thread가 시작되지 않았나요? " + thread.isAlive()); // false
System.out.println("Thread가 시작되었나요? " + thread.isStarted()); // false
thread.start();
System.out.println("Thread가 시작되었나요? " + thread.isStarted()); // true
System.out.println("Thread가 살아있나요? " + thread.isAlive()); // true
}
}
이 예시는 Thread가 시작되기 전에 Thread::isStarted() 메서드를 호출한 후, Thread::start() 메서드를 호출한 후 Thread::isStarted() 메서드를 호출하는 것을 보여줍니다.
2025-07-10 08:26