Thread를 확장하는 클래스가 있으며 시작될 때 jar의 Main 메서드가 실행됩니다. 스레드를 종료하면 시작된 프로세스가 종료되지 않습니다. 어떻게해야합니까? 감사!jar를 실행하는 스레드 종료
다음은 내 사용자 정의 Thread 클래스의 run() 메소드입니다.
@Override
public void run() {
if(parent != null) {
MessageConsole console = new MessageConsole(parent.getConsole().getTextPane());
console.redirectOut(new Color(240, 240, 240), null);
console.redirectErr(Color.RED, null);
console.setMessageLines(20);
}
if(oParent != null) {
MessageConsole console = new MessageConsole(oParent.getConsole().getTextPane());
console.redirectOut(new Color(240, 240, 240), null);
console.redirectErr(Color.RED, null);
console.setMessageLines(20);
}
try {
somejar.SomeJar.main(args);
} catch (Exception ex) {
System.err.println("Engine failed to start!\nSuggestion: Restart the application, and if the issue is not fixed reinstall the application.");
}
}
@Stephen C는 이것이 최선의 해결책이라고 동의합니다. 옵션이 아닌 경우, 하위 스레드를 식별 할 수있는 한 가지 방법은 새 ThreadGroup에서 첫 번째 스레드를 시작하는 것이며, 하위 그룹은 기본적으로 동일한 그룹에서 시작됩니다. 그것의 신뢰성은 없지만 아무것도없는 것보다 낫을 수 있습니다. –
@Peter Lawrey - ThreadGroups는 너무 신뢰할 수 없습니다. 예를 들어, 의존한다면 JAR 쓰레드에 의해 "소유"되지 않은 쓰레드가 종료 될 수 있습니다. 그것은 아무것도 아닌 것보다 나쁠 수 있습니다. –
거기에 내가 모든 아이들을 통해 열거하고 각각을 죽일 수있는 방법이 있습니까? 또는 각 스레드의 프로세스 ID를 가져 와서 개별적으로 종료 할 수 있습니까? – Jakir00