Source:
public void run() { while (true) { this.setThreadToDefaultState(); if(this.isInterrupted()) return; String exceptionMessage = null; String skippedMembersMessage = null; boolean failedDueToException = false; Group group = null; try { group = poolOfGroupsToBeSynchronized.takeJob(); } catch (InterruptedException ex) { log.error("Thread was interrupted when trying to take another group to synchronize from pool", ex); this.interrupt(); return; } try { startTime = System.currentTimeMillis(); log.debug("Synchronization thread started synchronization for group {}.", group); List<String> skippedMembers = perunBl.getGroupsManagerBl().synchronizeGroup(sess, group); skippedMembersMessage = prepareSkippedObjectsMessage(skippedMembers, "members"); exceptionMessage = skippedMembersMessage; log.debug("Synchronization thread for group has finished in ms.", group, System.currentTimeMillis() - startTime); } catch (WrongAttributeValueException | WrongReferenceAttributeValueException | InternalErrorException | WrongAttributeAssignmentException | GroupNotExistsException | AttributeNotExistsException | ExtSourceNotExistsException e) { failedDueToException = true; exceptionMessage = "Cannot synchronize group "; log.error(exceptionMessage + group, e); exceptionMessage += "due to exception: " + e.getName() + " => " + e.getMessage(); } catch (Exception e) { failedDueToException = true; exceptionMessage = "Cannot synchronize group "; log.error(exceptionMessage + group, e); exceptionMessage += "due to unexpected exception: " + e.getClass().getName() + " => " + e.getMessage(); } finally { try { perunBl.getGroupsManagerBl().saveInformationAboutGroupSynchronizationInNewTransaction(sess, group, failedDueToException, exceptionMessage); } catch (Exception ex) { log.error("When synchronization group " + group + ", exception was thrown.", ex); log.info("Info about exception from synchronization: " + skippedMembersMessage); } if(!poolOfGroupsToBeSynchronized.removeJob(group)) { log.error("Can't remove running job for object " + group + " from pool of running jobs because it is not containing it."); } log.debug("GroupSynchronizerThread finished for group: {}", group); } } }

Target:
public void run() { while (true) { this.setThreadToDefaultState(); if(this.isInterrupted()) return; String exceptionMessage = null; String skippedMembersMessage = null; boolean failedDueToException = false; Group group = null; try { group = poolOfGroupsToBeSynchronized.takeJob(); } catch (InterruptedException ex) { log.error("Thread was interrupted when trying to take another group to synchronize from pool", ex); this.interrupt(); return; } try { startTime = System.currentTimeMillis(); log.debug("Synchronization thread started synchronization for group {}.", group); List<String> skippedMembers = perunBl.getGroupsManagerBl().synchronizeGroup(sess, group); skippedMembersMessage = prepareSkippedObjectsMessage(skippedMembers, "members"); exceptionMessage = skippedMembersMessage; log.debug("Synchronization thread for group has finished in ms.", group, System.currentTimeMillis() - startTime); } catch (WrongAttributeValueException | WrongReferenceAttributeValueException | InternalErrorException | WrongAttributeAssignmentException | GroupNotExistsException | AttributeNotExistsException | ExtSourceNotExistsException e) { failedDueToException = true; exceptionMessage = "Cannot synchronize group "; log.error(exceptionMessage + group, e); exceptionMessage += "due to exception: " + e.getName() + " => " + e.getMessage(); } catch (Exception e) { failedDueToException = true; exceptionMessage = "Cannot synchronize group "; log.error(exceptionMessage + group, e); exceptionMessage += "due to unexpected exception: " + e.getClass().getName() + " => " + e.getMessage(); } finally { try { perunBl.getGroupsManagerBl().saveInformationAboutGroupSynchronizationInNewTransaction(sess, group, failedDueToException, exceptionMessage); } catch (Exception ex) { log.error("When synchronization group " + group + ", exception was thrown.", ex); log.error("Info about exception from synchronization: {}", skippedMembersMessage); } if(!poolOfGroupsToBeSynchronized.removeJob(group)) { log.error("Can't remove running job for object " + group + " from pool of running jobs because it is not containing it."); } log.debug("GroupSynchronizerThread finished for group: {}", group); } } }