From: adam Date: Wed, 11 Aug 2004 01:35:57 +0000 (+0000) Subject: handle thread-kills gracefully X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=5b0f0036720a7cb14bac29b4b319996745d30ab8;p=org.ibex.mail.git handle thread-kills gracefully darcs-hash:20040811013557-5007d-bafffe43510091d5fae6e4e16affca6b6987e8e8.gz --- diff --git a/src/org/ibex/mail/protocol/SMTP.java b/src/org/ibex/mail/protocol/SMTP.java index 8ee0ce3..b025ce0 100644 --- a/src/org/ibex/mail/protocol/SMTP.java +++ b/src/org/ibex/mail/protocol/SMTP.java @@ -162,18 +162,28 @@ public class SMTP { Log.setThreadAnnotation("[outgoing smtp] "); Log.info(SMTP.Outgoing.class, "outgoing thread started; " + spool.count(Query.all()) + " messages to send"); while(true) { + if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); for(Mailbox.Iterator it = spool.iterator(); it.next(); ) { - try { if (attempt(it.cur())) it.delete(); } - catch (Exception e) { Log.error(SMTP.Outgoing.class, e); } + try { + if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); + if (attempt(it.cur())) it.delete(); + } catch (Exception e) { + if (e instanceof InterruptedException) throw e; + Log.error(SMTP.Outgoing.class, e); + } } synchronized(Outgoing.class) { + if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); Log.info(SMTP.Outgoing.class, "outgoing thread going to sleep"); Outgoing.class.wait(5 * 60 * 1000); deadHosts.clear(); Log.info(SMTP.Outgoing.class,"outgoing thread woke up; "+spool.count(Query.all())+" messages in queue"); } } - } catch (Exception e) { Log.error(SMTP.Outgoing.class, e); } + } catch (Exception e) { + Log.error(SMTP.Outgoing.class, "outgoing thread killed by exception: " + e); + Log.error(SMTP.Outgoing.class, e); + } } }