I am developing a java email application using Timer, I have two arraylists named ActiveProcesses, InActiveProcesses. If I run the timer, it will send an email with InActiveProcesses list values ββfor every second. But the problem is that the timer is sent by email if the values ββof the InActiveProcesses list are the same. For example, the InActiveProcess list contains the value abcd , it will send an email every second with the same List values. I want to send an email, only the InActiveProcesses list contains different values. The timer checks the values ββevery second, if the values ββare different, it will send an email. How to deal with this problem using java. Thank you in advance. Here is the code
for (int i = 0; i < InActiveProcess.size(); i++) { if (!ActiveProcess.contains(InActiveProcess.get(i))) { list3.add(InActiveProcess.get(i)); } } for (int i = 0; i < ActiveProcess.size(); i++) { if (!InActiveProcess.contains(ActiveProcess.get(i))) { list3.add(ActiveProcess.get(i)); } } log.info("Processes which are Not Running: " + list3); StringBuilder sb = new StringBuilder(); for (int k = 0; k < list3.size(); k++) { Result = list3.get(k); sb.append(Result.toString()); sb.append(" "); } String message = sb.toString(); log.info(message); sms.SendMessage("1254554555", message); es.SendMail(" abcdr@gmail.com ", " Server process is down", message);
This is my Timer class.
int delay = 5000; // delay for 5 sec. int interval = 1000; // iterate every sec. Timer timer = new Timer(); timer.scheduleAtFixedRate(new sample() { }, delay, interval);
The timer runs the sample() class for every second and sends an email to the specified address. I want to handle a timer that will run every second at the same time, an email is es.SendMail(" abcdr@gmail.com ", " Server process is down", message); if message contains values.
source share