I am a bit new to the ExecutorService, and I am having a problem with it. I have this class:
@Override
public void updateAvatar(final MultipartFile multipartFile, final String speakerId) {
final GridFS avatarGfs = new GridFS(getTemplate().getDb(), SPEAKER_AVATAR_COLLECTION);
// Remove all sizes
avatarGfs.remove(new BasicDBObject(SPEAKER_ID_FIELD, speakerId));
System.out.println("hello from updateAvatar");
ExecutorService executorService = Executors.newFixedThreadPool(3);
executorService.execute(new Runnable() {
public void run() {
for (SpeakerAvatarSize size : SpeakerAvatarSize.values()) {
try {
System.out.println("calling saveAvatar");
saveAvatar(multipartFile, speakerId, size, avatarGfs);
} catch (IOException e) {
LOG.error("SpeakerRepository#updateAvatar", e);
}
}
}
});
executorService.shutdown();
System.out.println("shut down threads");
}
And I get this this error when editing a current user avatar and also when adding another avatar. It seems that only 1 avatar is added:
Exception in thread "pool-2-thread-1" java.lang.IllegalStateException: File has been moved - cannot be read again
at org.springframework.web.multipart.commons.CommonsMultipartFile.getInputStream(CommonsMultipartFile.java:123)
at util.ImageScaleUtil.scale(ImageScaleUtil.java:26)
at impl.SpeakerRepository.saveAvatar(SpeakerRepository.java:97)
at impl.SpeakerRepository.access$000(SpeakerRepository.java:28)
at impl.SpeakerRepository$1.run(SpeakerRepository.java:81)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Thank you in advance!