First of all I would like to tell I checked When does a Java Thread reach the 'Die' State and Why my thread did not die? before posting this.
It's all about Threads in Java. I am suspecting new inserted threads in my code (server side) to be the cause of the "java.lang.OutOfMemoryError: Java heap space" error I am getting every 2 days approximately (seems it's when Google's robots come to my application for SEO)...
Before using threads, I used to have my tomcat server running on 128MB without problem. After inserting threads, my tomcat server is running on 350 MB with a need to restart it every 2 days.
Here is, in general, my threads's pattern :
public Boolean sendEmailInThread(String emailAddress, String message) throws IllegalArgumentException {
try {
new Thread(new Runnable() {
@Override
public void run() {
try {
sendEmail.sendMessage(emailAddress, message);
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}
}).start();
} catch (Exception e) {
e.printStackTrace(System.out);
}
return true;
}
QUESTIONS : Is it 100% sure that the thread above will die after every instructions in the "run" are done ? Or is there a risk of memory leaking ?
Thank you in advance,