A join()은 Thread 클래스의 final 메서드이며, 스레드 실행 시작을 다른 스레드 실행 종료와 결합하여 스레드 실행이 시작되지 않도록 하는 데 사용할 수 있습니다. 다른 스레드가 끝날 때까지. join() 메서드가 스레드 인스턴스에서 호출되면 현재 실행 중인 스레드는 스레드 인스턴스의 실행이 완료될 때까지 차단됩니다.
public final void join() throws InterruptedException
public class JoinTest extends Thread { public void run() { for(int i=1; i <= 3; i++) { try { Thread.sleep(1000); } catch(Exception e) { System.out.println(e); } System.out.println("TutorialsPoint "+ i); } } public static void main(String args[]) { JoinTest t1 = new JoinTest(); JoinTest t2 = new JoinTest(); JoinTest t3 = new JoinTest(); t1.start(); try { <strong> t1.join(); // calling join() method </strong> } catch(Exception e) { System.out.println(e); } t2.start(); t3.start(); } }
TutorialsPoint 1 TutorialsPoint 2 TutorialsPoint 3 TutorialsPoint 1 TutorialsPoint 1 TutorialsPoint 2 TutorialsPoint 2 TutorialsPoint 3 TutorialsPoint 3
위 내용은 Java에서 Join() 메소드의 중요성은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!