スレッド側で計算結果の値を保持し、その値へのアクセサメソッドを用意しておく方法でどうでしょう。
(コード例)
`
public class ThreadTest {
public static void main(String[] args) {
try {
MyThread th = new MyThread();
th.start();
//スレッド終了まで待機
th.join();
System.out.println("計算結果 = " + th.getCnt());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
static class MyThread extends Thread {
private int count;
public void run() {
try {
//計算処理
for (int i = 1; i <= 100; i ++) {
count = count + 1;
}
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public int getCnt() {
return count;
}
}
}
`
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。