나는 읽을 수 있도록 여러 스레드에서 공유해야하는 문자열 목록 (tagList)을 가지고 있으므로 수정할 수없는 버전을 만들어 스레드에 전달합니다. 스레드는 그 목록 만 읽을 수 있으므로 스레드 안전성 여부는 확실하지 않습니다. 나는 괜찮을 것 같아요?은 수정할 수없는 스레드 목록 안전합니까?
스레드에 unmodifialble 목록을 전달할 때 단일 복사본을 전달하고 스레드가 공유합니까? 아니면 여러 복사본을 만들고 각 스레드에 복사본 하나를 전달합니까? (이 수정 될 수 없기 때문에)
final List<String> tList = Collections.unmodifiableList(tagList);
List<Future<Void>> calls = new ArrayList<Future<Void>>();
FileStatus[] fsta = _fileSystem.listStatus(p);
for (FileStatus sta : fsta) {
final Path path = new Path(sta.getPath(), "data.txt");
if (!_fileSystem.exists(path)) {
continue;
}
else {
calls.add(_exec.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
filterData(path, tList);
return null;
}
}));
}
}
스레드로부터 안전합니다. – jdb