私はスレッドを拡張するクラスを持っており、起動するとjarのMainメソッドが実行されます。スレッドを終了すると、開始したプロセスは終了しません。それについてどうすればいいですか?ありがとう!jarを実行するスレッドを終了する
私のカスタムスレッドクラスの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は、これが最適なソリューションであると考えています。そのオプションでない場合、子スレッドを識別する方法の1つは、新しいスレッドグループで最初のスレッドを開始することです。子グループはデフォルトで同じグループ内で開始されます。それは信頼できるものではありませんが、何よりも良いかもしれません。 –
@Peter Lawrey - ThreadGroupsはあまりにも信頼性がありません。たとえば、それらに頼った場合、JARスレッドが所有していないスレッドを強制終了させる可能性があります。それは何もないよりも激しいことがあります。 –
私はすべての子供たちを列挙してそれぞれを殺すことができる方法はありますか?あるいは、各スレッドのプロセスIDを取得し、個別に終了させることができますか? – Jakir00