Reputation: 8790
I am reading a log file and sending mails if anything of concern happens in the log file.Both the processes are happening simultaneously.but what i saw was lines are read properly but sometimes the mails are skipped,so i put the mailing part in a thread.Now this is not a standalone program,it is running in a container so when i stop the tomcat server,memory leakage problem arises as it is not able to stop the thread which i made to send mail.can anyone help..This is what i am doing.
--Read Log file--
|
|
new Thread(new Runnable() {
@Override
public void run() {
SendMail mail = new SendMail();
String mailDetails="";
mailDetails = loginfo;
loginfo = " ";
mail.sendNotification()
}
Upvotes: 0
Views: 86
Reputation: 5654
The answer is you stop a thread by using interrupt(). This article covers some of the background to stopping threads and the suggested alternatives and discusses why interrupt() is the answer
In short, you can use the following after you send the mail:
Thread thisThread = Thread.currentThread();
thisThread.interrupt();
Upvotes: 1