Source:
<code>public void sendEmailToEndorseds() { CronJob cronJob = new CronJob(); cronJob.setName(Constants.CRON_MAIL_ENDORSEMENT_JOB); cronJob.setStartTimestamp(new Date()); try { List<TechGalleryUser> usersList = techGalleryUserDao.findAll(); for (TechGalleryUser techGalleryUser : usersList) { List<Endorsement> endorsementsList = endorsementDao.findAllEndorsementsStartingFrom(techGalleryUser, <START> findLastExecutedCronJob(Constants.CRON_MAIL_ENDORSEMENT_JOB)); <END> if (endorsementsList != null) { TechGalleryActivitiesTO activities = new TechGalleryActivitiesTO(); activities.setTechnologyActivitiesTo(new ArrayList<TechnologyActivitiesTO>()); activities.setAppName(Constants.APP_NAME); activities.setTimestamp(new Date()); for (Endorsement endorsement : endorsementsList) { TechnologyActivitiesTO endorsementActivity = new TechnologyActivitiesTO(); endorsementActivity.setEndorserUser(endorsement.getEndorserEntity()); endorsementActivity.setTechnology(endorsement.getTechnologyEntity()); activities.getTechnologyActivitiesTo().add(endorsementActivity); } if (!activities.getTechnologyActivitiesTo().isEmpty()) { EmailConfig email = new EmailConfig(EmailTypeEnum.ENDORSED, EmailTypeEnum.ENDORSED.getSubject() + activities.getFormattedTimestamp(), activities, techGalleryUser.getEmail()); emailService.push(email); } } } cronJob.setEndTimestamp(new Date()); cronJob.setCronStatus(CronStatus.SUCCESS); } catch (Exception e) { _LOG.info(e.getMessage()); cronJob.setEndTimestamp(new Date()); cronJob.setCronStatus(CronStatus.FAILURE); cronJob.setDescription(e.getMessage()); } cronJobsDao.add(cronJob); }</code><technical_language>@tsr-thulio entering in this iteration recover 'findLastExecutedCronJob'. In recover this timestamp instead of N times</technical_language>

Target:
public void sendEmailToEndorseds() { CronJob cronJob = new CronJob(); cronJob.setName(Constants.CRON_MAIL_ENDORSEMENT_JOB); cronJob.setStartTimestamp(new Date()); Date lastExecutedCronJob = findLastExecutedCronJob(Constants.CRON_MAIL_ENDORSEMENT_JOB); try { List<TechGalleryUser> usersList = techGalleryUserDao.findAll(); for (TechGalleryUser techGalleryUser : usersList) { List<Endorsement> endorsementsList = endorsementDao.findAllEndorsementsStartingFrom(techGalleryUser, lastExecutedCronJob); if (endorsementsList != null) { TechGalleryActivitiesTO activities = new TechGalleryActivitiesTO(Constants.APP_NAME, null, new ArrayList<TechnologyActivitiesTO>()); for (Endorsement endorsement : endorsementsList) { TechnologyActivitiesTO endorsementActivity = new TechnologyActivitiesTO(endorsement.getEndorserEntity(), endorsement.getTechnologyEntity(), null, null, null); activities.getTechnologyActivitiesTo().add(endorsementActivity); } if (!activities.getTechnologyActivitiesTo().isEmpty()) { EmailConfig email = new EmailConfig(EmailTypeEnum.ENDORSED, EmailTypeEnum.ENDORSED.getSubject() + activities.getFormattedTimestamp(), activities, techGalleryUser.getEmail()); emailService.push(email); } } } cronJob.setEndTimestamp(new Date()); cronJob.setCronStatus(CronStatus.SUCCESS); } catch (Exception e) { _LOG.info(e.getMessage()); cronJob.setEndTimestamp(new Date()); cronJob.setCronStatus(CronStatus.FAILURE); cronJob.setDescription(e.getMessage()); } cronJobsDao.add(cronJob); }