Problem with Shutdown Hooks involving multiple class calls
Ok,
I am working on a program for a jsp page where e-mail messages are queued in my MailQueue class and stored when they cannot be sent out through the mail server. The problem I am having is that we want to be able to write the e-mail objects to a file when our server is shutdown so I am trying to employ a shutdown hook to call my function that creates the output file. The problem is I have a MailQueue class where the messages are stored that employs a _mailQueue singleton. I have another class, MailArchive, that employs the functionality of writing and reading from a file and requires a MailQueue object for the object writing methods. Of course this is not all the code but the programs are quite extensive spanning many classes so I did not feel it would be prudent to try and post it all here. I understand if that makes it more difficult to give advice. The _mailQueue object is intialized so don't think that the value stay = null. This is the last thing I came up with along with trying about anything else I could imagine and I can't get anything to push through, the logger shows that the startShutdownHook() method is getting called so the thread should be getting registered with the JVM, but I don't even know if you can do this type of thing with a jsp. If you have any questions about missing code, or any advice that could be offered would be appreciated. I have tried simpler versions of this and it works fine until I try to reference the class that the shutdown hook subclass is a part of and then everything falls apart for me. Sorry about the formatting I kinda n00bed it up before putting the code tags in, lol.
MailQueue:
privatestatic MailQueue _mailQueue =null;
publicvoid startShutdownHook(){
ArchiveShutdownHook archiveShutdownHook =new ArchiveShutdownHook();
Runtime.getRuntime().addShutdownHook(archiveShutdownHook);
//LOG.debug("SHUTDOWN HOOK has been called.");
}
publicclass ArchiveShutdownHookextends Thread{
publicvoid run(){
try{
MailArchive mailArchive =new MailArchive();
mailArchive.archiveAll(_mailQueue);
}
catch(Exception e){
}
}
}
MailArchive:
publicvoid archiveAll(MailQueue mailQueue)throws Exception{
archiveSimpleMail(mailQueue);
archiveMimeMessages(mailQueue);
}
mail.jsp
MailArchive archive = (MailArchive) appContext.getBean("mailArchive");
MailQueue mailQueue = MailQueue.getInstance(sender, archive);
mailQueue.startShutdownHook();
Message was edited by:
rcrain
Message was edited by:
rcrain
Message was edited by:
rcrain
Message was edited by:
rcrain

