Доброго времени суток. Вроде здесь не должно возникать дедлока, но чет такое предчуствие, что возникает. Просто зависает и все, и то, это по праздникам бывает, отловить не могу.Вот код -
| Код | public void addPictureData(int parentGalleryId, ByteArrayOutputStream imageBytes, String pictureUrl, Date date) { synchronized (monitor/*финал объект*/) {
if (parGalIdPool.size() > 5) {
try { monitor.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } synchronized (this) { if (date != null) { Logger.log(ScaleImagesSaveToDbThread.class.getName(), "!!!adding icon to pool url = " + pictureUrl); } else { Logger.log(ScaleImagesSaveToDbThread.class.getName(), "!!!adding picture to pool url = " + pictureUrl); } parGalIdPool.add(parentGalleryId); imageBytesPool.add(imageBytes); pictureUrlPool.add(pictureUrl); datePool.add(date); this.notify(); }
} }
public void run() { while (true) { ByteArrayOutputStream imageBytes = null; int parGalId = -1; String pictureUrl = null; Date date = null; synchronized (this) { if (parGalIdPool.size() != 0) { parGalId = parGalIdPool.elementAt(0); imageBytes = imageBytesPool.elementAt(0); pictureUrl = pictureUrlPool.elementAt(0); date = datePool.elementAt(0); } else { try { this.wait(); continue; } catch (InterruptedException e) { e.printStackTrace(); } } }
try { if (date == null) { Logger.log(ScaleImagesSaveToDbThread.class.getName(), "add to db picture... url = " + pictureUrl); byte[] imageBytesData128 = scaleImage(imageBytes.toByteArray(), 120); byte[] imageBytesData176 = scaleImage(imageBytes.toByteArray(), 168); byte[] imageBytesData240 = scaleImage(imageBytes.toByteArray(), 232); byte[] imageBytesData352 = scaleImage(imageBytes.toByteArray(), 344);
DatabaseActionManager.addPicture(parGalId, pictureUrl, imageBytesData128, imageBytesData176, imageBytesData240, imageBytesData352); } else { Logger.log(ScaleImagesSaveToDbThread.class.getName(), "add to db gallery's icon...url = " + pictureUrl); byte[] imageBytesData128 = scaleImage(imageBytes.toByteArray(), 42); byte[] imageBytesData176 = scaleImage(imageBytes.toByteArray(), 58); byte[] imageBytesData240 = scaleImage(imageBytes.toByteArray(), 80); byte[] imageBytesData352 = scaleImage(imageBytes.toByteArray(), 117); DatabaseActionManager.updateSubGallery(pictureUrl, imageBytesData128, imageBytesData176, imageBytesData240, imageBytesData352); } } catch (DatabaseConnectionException e) { Logger.logError(RefreshDBThread.class.getName(), e.getMessage(), e); } catch (ImageFormatterException ife) { Logger.logError(RefreshDBThread.class.getName(), ife.getMessage(), ife); }
synchronized (this) { Logger.log(ScaleImagesSaveToDbThread.class.getName(), "removing from vector..."); parGalIdPool.remove(0); imageBytesPool.remove(0); pictureUrlPool.remove(0); datePool.remove(0); }
if (parGalIdPool.size() < 6) { Logger.log(ScaleImagesSaveToDbThread.class.getName(), "!!!try to notify monitor"); synchronized (monitor) { monitor.notify(); } } } }
|
У мну уже просто голова не варит, но на мой взгляд вроде как логически не должно дедлока случиться, но может я сильно ошибаюсь... Помогите плиз советом
Добавлено через 3 минуты и 44 секунды Да, класс этот - это синглтон, запускается при старте приложения. Из потока, в котором скачивается картинка с http, вызывается метод addPictureData() |