After clicking a button in my app, it creates new normal Thread and start downloading large image and saving it to file. Everything is going well, but when i click button more than once it's going without errors and when i try to view these images they're bugged like they re overwriting themself.
I don't have any idea how to debug it.
localPath = today + "/" + productCode + "/" + this.placeId; //Unique
/* ... */
private void productSave(String productCode, int whichCamera, boolean isError) {
for (int i = position; i < lastCamera; i++) {
Date dateSave = new Date();
path = localPath + "/" + dateFormat.format(dateSave) + "_" + (i + 1) + ".jpg";
try {
BufferedImage imageOld = ImageIO.read(new URL(this.camerasUrlsToSave[i]));
ImageIO.write(imageOld, "jpg", new File(rootPath + "/" + path));
ComDb.getInstance().saveProduct(productCode, this.placeId, path, dateSave);
} catch (IOException ex) {
result = false;
}
}
}
EDIT: path is 100% unique (different folders with product code). And it shoudn't be problem with image from camera - I can open 10 cards i dont see image bugs
EDIT2: Can it be something like downloading Img bufor? Cause all images are downloaded from the same IP. Or maybe its problem with bufferedimg memory leaks. Need idea how to repair it.
EDIT3: I found that if i open 5 cards in web browser with my camera address like : blah.blah.some.ip/GetImage.cgi?CH=0 They're loading one after the other, not all at once. But, i dont see bugged images when downloading ends.
EDIT4: I tried to reproduce this bug in web browser, if i try to open link in ff and in IE. IE prints "getImage busy". When I try ff and chrome i got broken images. So i have to do sth like queue or disable button ...
EDIT5: My temporary solution: synchronized function productSave. Images from second click will be saved few seconds later.