マルチスレッド用のJavaRunnable
インターフェイスを実装しています。いくつn
かのスレッドがあります。それぞれのスレッドには独自の寿命があります。すべてのスレッドの寿命が切れるまで待ちたいです。以下がその場合だとしましょう
for(int i = 0; i< k;i++){
Thread thread1 = new Thread(new xyz())
Thread thread2 = new Thread(new abc())
Thread thread3 = new Thread(new mno())
thread1.start();
thread2.start();
thread3.start();
}
私はそれを同期させるために以下を行っています。それが正しいかどうかはわかりません。どうすればいいですか?また、スレッド化されたプログラムが正しく機能しているかどうかを確認する方法はありますか?
if(thread2.isAlive())
try {
thread2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
if(thread1.isAlive())
try {
thread1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
if(thread3.isAlive())
try {
thread3.join();
} catch (InterruptedException e) {
e.printStackTrace();
}