svn commit: r1360691 - /ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1360691 - /ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java

jacopoc
Author: jacopoc
Date: Thu Jul 12 14:16:43 2012
New Revision: 1360691

URL: http://svn.apache.org/viewvc?rev=1360691&view=rev
Log:
Replaced usage of java.util.Timer with the more modern and reliable ScheduledThreadPool executor.

Modified:
    ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java?rev=1360691&r1=1360690&r2=1360691&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/mail/JavaMailContainer.java Thu Jul 12 14:16:43 2012
@@ -22,8 +22,9 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.Timer;
-import java.util.TimerTask;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 import javax.mail.FetchProfile;
 import javax.mail.Flags;
 import javax.mail.Folder;
@@ -62,7 +63,7 @@ public class JavaMailContainer implement
     protected GenericValue userLogin = null;
     protected long timerDelay = 300000;
     protected long maxSize = 1000000;
-    protected Timer pollTimer = null;
+    protected ScheduledExecutorService pollTimer = null;
     protected boolean deleteMail = false;    // whether to delete emails after fetching them.
 
     protected String configFile = null;
@@ -80,7 +81,7 @@ public class JavaMailContainer implement
         this.name = name;
         this.configFile = configFile;
         this.stores = new LinkedHashMap<Store, Session>();
-        this.pollTimer = new Timer();
+        this.pollTimer = Executors.newScheduledThreadPool(1);
     }
 
     /**
@@ -126,7 +127,7 @@ public class JavaMailContainer implement
 
         // start the polling timer
         if (UtilValidate.isNotEmpty(stores)) {
-            pollTimer.schedule(new PollerTask(dispatcher, userLogin), timerDelay, timerDelay);
+            pollTimer.scheduleAtFixedRate(new PollerTask(dispatcher, userLogin), timerDelay, timerDelay, TimeUnit.MILLISECONDS);
         } else {
             Debug.logWarning("No JavaMail Store(s) configured; poller disabled.", module);
         }
@@ -142,7 +143,7 @@ public class JavaMailContainer implement
      */
     public void stop() throws ContainerException {
         // stop the poller
-        this.pollTimer.cancel();
+        this.pollTimer.shutdown();
         Debug.logWarning("stop JavaMail poller", module);
     }
 
@@ -250,7 +251,7 @@ public class JavaMailContainer implement
         }
     }
 
-    class PollerTask extends TimerTask {
+    class PollerTask implements Runnable {
 
         LocalDispatcher dispatcher;
         GenericValue userLogin;
@@ -260,7 +261,6 @@ public class JavaMailContainer implement
             this.userLogin = userLogin;
         }
 
-        @Override
         public void run() {
             if (UtilValidate.isNotEmpty(stores)) {
                 for (Map.Entry<Store, Session> entry: stores.entrySet()) {