>>494
こんな感じで
class CreateList extends Thread {
private LinkedBlockingQueue <String> lineList = new LinkedBlockingQueue<String>();
private List<テスト> testList = new ArrayList<テスト>();
private Throwable throwable;
public void run() {
try {
while(true) {
String line = lineList.take();
if (line == null) break; // 終了用
testList.add(new テスト(line));
}
} catch (Throwable ex) { throwable = ex; }
}
public void addQueue(String line) { lineList.add(line); }
public List<テスト> getResult() throws Throwable{
lineList.add(null); // 終了用
join();
if (throwable != null) { throw throwable; }
return testList;
}
}
メイン側
while((line = br.readLine()) != null) { createList.addQueue(line); }
try {
List<テスト> testList = createList.getResult();
...
} catch (Throwable ex) { ... }