Hi carlos:
I think a nice way is to deploy a simple TimerTask inside any webapp to do this work. You could use anything like the following to help you:
import java.util.*; public class MemoryWatchDog extends TimerTask{
private static Timer currentTimer = null;
public static void startTimer() { if(currentTimer != null) return; int seconds = 60; Timer timer = new Timer(); timer.scheduleAtFixedRate(new WatchDog(), 1, (seconds * 1000)); currentTimer = timer; } }
public static void stopTimer() { if(currentTimer == null) return; currentTimer.cancel(); currentTimer = null; }
private WatchDog() { // Just for hide the constructor }
public void run() {
int long lowMemory = 5242880; // 5Mb
if(Runtime.getRuntime().freeMemory() <= lowMemory){
// Using Jakarta Commons-Email to do the hard work...
SimpleEmail email = new SimpleEmail();
email.setHostName("mail.myserver.com");
email.addTo("[EMAIL PROTECTED]","John Doe");
email.setFrom("[EMAIL PROTECTED]", "Tomcat");
email.setSubject("Warning!!!");
email.setMsg("Look at me! I won't have enough memory in few seconds!!!"
+ "\n Free memory (bytes): "
+ Runtime.getRuntime().freeMemory());
email.send();
}
}
}
[]'s Ronaldo Arrudas [EMAIL PROTECTED]
Carlos Rule wrote:
Hello all, newbie here.
Does anyone know if there is a reliable way of setting up an alert to tell
me whenever the Tomcat (5.0.25) process reaches a certain level of memory
usage?
Many thanks!
Carlos
smime.p7s
Description: S/MIME Cryptographic Signature