handle thread-kills gracefully
authoradam <adam@megacz.com>
Wed, 11 Aug 2004 01:35:57 +0000 (01:35 +0000)
committeradam <adam@megacz.com>
Wed, 11 Aug 2004 01:35:57 +0000 (01:35 +0000)
darcs-hash:20040811013557-5007d-bafffe43510091d5fae6e4e16affca6b6987e8e8.gz

src/org/ibex/mail/protocol/SMTP.java

index 8ee0ce3..b025ce0 100644 (file)
@@ -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);
+            }
         }
     }