Re: WorkManager replacement
Hi, When we needed that kind of functionality in tomcat we created an implementation of the old commonj.work and commonj.timer api using timers and threads. With that implementation we could port the application to websphere when needed. 2015-02-13 17:22 GMT-02:00 Terence M. Bandoian : > On 2/13/2015 8:52 AM, Kevin Hale Boyes wrote: > >> I'll look into the timers for sure. >> I've also noticed that my application (lots of code) also uses Executors >> and ExecutorService so I might do something there. >> >> One of the things that WorkManager gave us, and we take advantage of, is a >> callback handler that lets us know when the work was accepted for >> processing and when it was complete. I'll have to find replacements for >> that feature. Maybe that's easily done with Future's in the concurrency >> framework. >> >> Thanks for your help. >> Kevin >> >> On 13 February 2015 at 06:15, David kerber wrote: >> >> On 2/13/2015 7:29 AM, Daniel Mikusa wrote: >>> >>> On Thu, Feb 12, 2015 at 11:59 PM, Kevin Hale Boyes wrote: I currently have an application running on weblogic that I'm moving over > to > tomcat 8. > One of the things the application does is run background jobs using the > commonj WorkManager. These jobs are managed by weblogic which seems to > be > the recommended practice. > > What is the best/recommended way to run background jobs in Tomcat 8? > > > Personally I'd use Spring, which has a nice and simple way to schedule tasks. I'd also be using Spring for other things though and I'm not sure I'd pull it in just for scheduled tasks. I use java.util.timer for my scheduled jobs in tomcat. >>> >>> >>> >>> A quick google search came up with this library. http://commonj.myfoo.de/ Haven't personally used it though. I suppose another option would be to just use java.util.concurrent. Dan Thanks, > Kevin > > > I've used something similar to the following in the past: > > > public class AServletContextListener implements ServletContextListener > { > > private ScheduledExecutorService executor; > > > /** > * Constructs AServletContextListener object. > */ > > public AServletContextListener() > { > } > > > /** > * Invoked when context is initialized. > * > * @paramscetriggering ServletContextEvent > */ > > public void contextInitialized( ServletContextEvent sce ) > { > if ( executor == null ) > { > executor = Executors.newSingleThreadScheduledExecutor(); > > Calendar firstRunTime = new GregorianCalendar(); > firstRunTime.set( Calendar.HOUR_OF_DAY, 12 ); > firstRunTime.set( Calendar.MINUTE, 0 ); > firstRunTime.set( Calendar.SECOND, 0 ); > firstRunTime.set( Calendar.MILLISECOND, 0 ); > > executor.scheduleAtFixedRate( > new ARunnable(), > firstRunTime.getTimeInMillis() - > System.currentTimeMillis(), > 1000 * 60 * 60 * 24, > TimeUnit.MILLISECONDS ); > } > } > > > /** > * Invoked when context is destroyed. > * > * @paramscetriggering ServletContextEvent > */ > > public void contextDestroyed( ServletContextEvent sce ) > { > if ( executor != null ) > { > boolean isTerminated = false; > > executor.shutdown(); > > do > { > try > { > isTerminated = executor.awaitTermination( > 1, TimeUnit.SECONDS ); > } > catch ( InterruptedException ignore ) > { > } > } > while ( !isTerminated ); > > executor = null; > > Thread.yield(); > } > } > > } > > > It's simple, not very much code and gets the job done. The call to > Thread.yield was added to eliminate an error message in the Tomcat logs. > > -Terence Bandoian > > > > - > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > >
Re: WorkManager replacement
On 2/13/2015 8:52 AM, Kevin Hale Boyes wrote: I'll look into the timers for sure. I've also noticed that my application (lots of code) also uses Executors and ExecutorService so I might do something there. One of the things that WorkManager gave us, and we take advantage of, is a callback handler that lets us know when the work was accepted for processing and when it was complete. I'll have to find replacements for that feature. Maybe that's easily done with Future's in the concurrency framework. Thanks for your help. Kevin On 13 February 2015 at 06:15, David kerber wrote: On 2/13/2015 7:29 AM, Daniel Mikusa wrote: On Thu, Feb 12, 2015 at 11:59 PM, Kevin Hale Boyes wrote: I currently have an application running on weblogic that I'm moving over to tomcat 8. One of the things the application does is run background jobs using the commonj WorkManager. These jobs are managed by weblogic which seems to be the recommended practice. What is the best/recommended way to run background jobs in Tomcat 8? Personally I'd use Spring, which has a nice and simple way to schedule tasks. I'd also be using Spring for other things though and I'm not sure I'd pull it in just for scheduled tasks. I use java.util.timer for my scheduled jobs in tomcat. A quick google search came up with this library. http://commonj.myfoo.de/ Haven't personally used it though. I suppose another option would be to just use java.util.concurrent. Dan Thanks, Kevin I've used something similar to the following in the past: public class AServletContextListener implements ServletContextListener { private ScheduledExecutorService executor; /** * Constructs AServletContextListener object. */ public AServletContextListener() { } /** * Invoked when context is initialized. * * @paramscetriggering ServletContextEvent */ public void contextInitialized( ServletContextEvent sce ) { if ( executor == null ) { executor = Executors.newSingleThreadScheduledExecutor(); Calendar firstRunTime = new GregorianCalendar(); firstRunTime.set( Calendar.HOUR_OF_DAY, 12 ); firstRunTime.set( Calendar.MINUTE, 0 ); firstRunTime.set( Calendar.SECOND, 0 ); firstRunTime.set( Calendar.MILLISECOND, 0 ); executor.scheduleAtFixedRate( new ARunnable(), firstRunTime.getTimeInMillis() - System.currentTimeMillis(), 1000 * 60 * 60 * 24, TimeUnit.MILLISECONDS ); } } /** * Invoked when context is destroyed. * * @paramscetriggering ServletContextEvent */ public void contextDestroyed( ServletContextEvent sce ) { if ( executor != null ) { boolean isTerminated = false; executor.shutdown(); do { try { isTerminated = executor.awaitTermination( 1, TimeUnit.SECONDS ); } catch ( InterruptedException ignore ) { } } while ( !isTerminated ); executor = null; Thread.yield(); } } } It's simple, not very much code and gets the job done. The call to Thread.yield was added to eliminate an error message in the Tomcat logs. -Terence Bandoian - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: WorkManager replacement
We use quartz already for scheduled tasks but the work that I'm talking about doesn't necessarily happen on a timer. The main use for us is the asynchronous execution of work once we've figured out which node in our cluster should handle it. I'm still going to consider java.util.concurrent since we use it elsewhere but I'm also going to look more into Spring. Thanks for your help, Kevin. On 13 February 2015 at 09:32, Christopher Schultz < ch...@christopherschultz.net> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA256 > > Dan, > > On 2/13/15 7:29 AM, Daniel Mikusa wrote: > > On Thu, Feb 12, 2015 at 11:59 PM, Kevin Hale Boyes > > wrote: > > > >> I currently have an application running on weblogic that I'm > >> moving over to tomcat 8. One of the things the application does > >> is run background jobs using the commonj WorkManager. These jobs > >> are managed by weblogic which seems to be the recommended > >> practice. > >> > >> What is the best/recommended way to run background jobs in Tomcat > >> 8? > >> > > > > Personally I'd use Spring, which has a nice and simple way to > > schedule tasks. I'd also be using Spring for other things though > > and I'm not sure I'd pull it in just for scheduled tasks. > > > > A quick google search came up with this library. > > > > http://commonj.myfoo.de/ > > > > Haven't personally used it though. > > > > I suppose another option would be to just use > > java.util.concurrent. > > That amounts to rolling-your-own. If you just need to do something on > a rough schedule, then java.util.concurrent is fine: start a thread > that does something every 10 minutes or whatever. > > If you want real scheduling, you want something like Quartz: > http://quartz-scheduler.org/ > > I would argue that there are better solutions than using Quartz from > within your own web application, but it depends upon your perspective. > > - -chris > -BEGIN PGP SIGNATURE- > Version: GnuPG v1 > Comment: GPGTools - http://gpgtools.org > > iQIcBAEBCAAGBQJU3icEAAoJEBzwKT+lPKRY9bIP/ilEoImpKncX82WU+SqgQQgP > zUhUTP0x+bntXNpouuxbb1NOhHKH6d7l0p2WKkQRoKf2qxJzxYhEnAiBELCI7CQF > 02OrXnzl4VmatgVgd5Aom/7QIzhLArLKNosGwIS8d/BbssPcZS6plBTU70VS8C7D > I+QON7RW3veJG9SFFA5sKrGhlgFuDUTbrLcz/oZeZ2xdbg4s2htAH9B+XNz5Gbvv > NKESUASPTGzYCSwZhgwIVoxZZavdkCwVvSJIEyPDlGwMDrBkYdSg/GbctyHA8Mny > METMmlN9Q29mEc6/VNSv6B+XtqUWCPud0WAPZm6rIso7NaV/ScY+/L19lzvLOn1a > SvwYavQ8bdGWb+w5xIcnsnZkLknwaDJoYMerquwnCxsPqaAdBygdku8OuvA8PxT4 > eIlUCOoT5GjxWTEX+HIWBvyx2KXTM8EScYdyXCuGtxnKcpexYaXBJQ2GhNc4EHym > T3JiLu/fAIu4TWyI6oM64YLMfJfNk49gNtPCjWfRluG4qqKQ3YqjQubf8FIe/vOe > y1wXzC/7KtV1urLDL74mLTjGpihiig3e9CRa7MWK354K/WoSlgbkze/Ac1df40g+ > Zq1MpgnGQmjgvG16FGujeL5U+QlwFTXYNAqXKsP0++FJJ9DEhkQM8c0yYlDplOYZ > xFKob5fnVsgVj1flZH4N > =aLoS > -END PGP SIGNATURE- > > - > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > >
Re: WorkManager replacement
Spring is starting to appear to be the best choice. Thanks for the reference. On 13 February 2015 at 08:04, Daniel Mikusa wrote: > On Fri, Feb 13, 2015 at 9:49 AM, Kevin Hale Boyes > wrote: > > > We already use Spring in the project so I'll have a look there. > > > > > http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#scheduling > > Dan > > > > Thanks > > > > On 13 February 2015 at 05:29, Daniel Mikusa wrote: > > > > > On Thu, Feb 12, 2015 at 11:59 PM, Kevin Hale Boyes > > > wrote: > > > > > > > I currently have an application running on weblogic that I'm moving > > over > > > to > > > > tomcat 8. > > > > One of the things the application does is run background jobs using > the > > > > commonj WorkManager. These jobs are managed by weblogic which seems > to > > > be > > > > the recommended practice. > > > > > > > > What is the best/recommended way to run background jobs in Tomcat 8? > > > > > > > > > > Personally I'd use Spring, which has a nice and simple way to schedule > > > tasks. I'd also be using Spring for other things though and I'm not > sure > > > I'd pull it in just for scheduled tasks. > > > > > > A quick google search came up with this library. > > > > > >http://commonj.myfoo.de/ > > > > > > Haven't personally used it though. > > > > > > I suppose another option would be to just use java.util.concurrent. > > > > > > Dan > > > > > > > > > > > > > > Thanks, > > > > Kevin > > > > > > > > > >
Re: WorkManager replacement
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Dan, On 2/13/15 7:29 AM, Daniel Mikusa wrote: > On Thu, Feb 12, 2015 at 11:59 PM, Kevin Hale Boyes > wrote: > >> I currently have an application running on weblogic that I'm >> moving over to tomcat 8. One of the things the application does >> is run background jobs using the commonj WorkManager. These jobs >> are managed by weblogic which seems to be the recommended >> practice. >> >> What is the best/recommended way to run background jobs in Tomcat >> 8? >> > > Personally I'd use Spring, which has a nice and simple way to > schedule tasks. I'd also be using Spring for other things though > and I'm not sure I'd pull it in just for scheduled tasks. > > A quick google search came up with this library. > > http://commonj.myfoo.de/ > > Haven't personally used it though. > > I suppose another option would be to just use > java.util.concurrent. That amounts to rolling-your-own. If you just need to do something on a rough schedule, then java.util.concurrent is fine: start a thread that does something every 10 minutes or whatever. If you want real scheduling, you want something like Quartz: http://quartz-scheduler.org/ I would argue that there are better solutions than using Quartz from within your own web application, but it depends upon your perspective. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1 Comment: GPGTools - http://gpgtools.org iQIcBAEBCAAGBQJU3icEAAoJEBzwKT+lPKRY9bIP/ilEoImpKncX82WU+SqgQQgP zUhUTP0x+bntXNpouuxbb1NOhHKH6d7l0p2WKkQRoKf2qxJzxYhEnAiBELCI7CQF 02OrXnzl4VmatgVgd5Aom/7QIzhLArLKNosGwIS8d/BbssPcZS6plBTU70VS8C7D I+QON7RW3veJG9SFFA5sKrGhlgFuDUTbrLcz/oZeZ2xdbg4s2htAH9B+XNz5Gbvv NKESUASPTGzYCSwZhgwIVoxZZavdkCwVvSJIEyPDlGwMDrBkYdSg/GbctyHA8Mny METMmlN9Q29mEc6/VNSv6B+XtqUWCPud0WAPZm6rIso7NaV/ScY+/L19lzvLOn1a SvwYavQ8bdGWb+w5xIcnsnZkLknwaDJoYMerquwnCxsPqaAdBygdku8OuvA8PxT4 eIlUCOoT5GjxWTEX+HIWBvyx2KXTM8EScYdyXCuGtxnKcpexYaXBJQ2GhNc4EHym T3JiLu/fAIu4TWyI6oM64YLMfJfNk49gNtPCjWfRluG4qqKQ3YqjQubf8FIe/vOe y1wXzC/7KtV1urLDL74mLTjGpihiig3e9CRa7MWK354K/WoSlgbkze/Ac1df40g+ Zq1MpgnGQmjgvG16FGujeL5U+QlwFTXYNAqXKsP0++FJJ9DEhkQM8c0yYlDplOYZ xFKob5fnVsgVj1flZH4N =aLoS -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: WorkManager replacement
On Fri, Feb 13, 2015 at 9:49 AM, Kevin Hale Boyes wrote: > We already use Spring in the project so I'll have a look there. > http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#scheduling Dan > Thanks > > On 13 February 2015 at 05:29, Daniel Mikusa wrote: > > > On Thu, Feb 12, 2015 at 11:59 PM, Kevin Hale Boyes > > wrote: > > > > > I currently have an application running on weblogic that I'm moving > over > > to > > > tomcat 8. > > > One of the things the application does is run background jobs using the > > > commonj WorkManager. These jobs are managed by weblogic which seems to > > be > > > the recommended practice. > > > > > > What is the best/recommended way to run background jobs in Tomcat 8? > > > > > > > Personally I'd use Spring, which has a nice and simple way to schedule > > tasks. I'd also be using Spring for other things though and I'm not sure > > I'd pull it in just for scheduled tasks. > > > > A quick google search came up with this library. > > > >http://commonj.myfoo.de/ > > > > Haven't personally used it though. > > > > I suppose another option would be to just use java.util.concurrent. > > > > Dan > > > > > > > > > > Thanks, > > > Kevin > > > > > >
Re: WorkManager replacement
I'll look into the timers for sure. I've also noticed that my application (lots of code) also uses Executors and ExecutorService so I might do something there. One of the things that WorkManager gave us, and we take advantage of, is a callback handler that lets us know when the work was accepted for processing and when it was complete. I'll have to find replacements for that feature. Maybe that's easily done with Future's in the concurrency framework. Thanks for your help. Kevin On 13 February 2015 at 06:15, David kerber wrote: > On 2/13/2015 7:29 AM, Daniel Mikusa wrote: > >> On Thu, Feb 12, 2015 at 11:59 PM, Kevin Hale Boyes >> wrote: >> >> I currently have an application running on weblogic that I'm moving over >>> to >>> tomcat 8. >>> One of the things the application does is run background jobs using the >>> commonj WorkManager. These jobs are managed by weblogic which seems to >>> be >>> the recommended practice. >>> >>> What is the best/recommended way to run background jobs in Tomcat 8? >>> >>> >> Personally I'd use Spring, which has a nice and simple way to schedule >> tasks. I'd also be using Spring for other things though and I'm not sure >> I'd pull it in just for scheduled tasks. >> > > I use java.util.timer for my scheduled jobs in tomcat. > > > >> A quick google search came up with this library. >> >> http://commonj.myfoo.de/ >> >> Haven't personally used it though. >> >> I suppose another option would be to just use java.util.concurrent. >> >> Dan >> >> >> >>> Thanks, >>> Kevin >>> >>> >> > > - > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > >
Re: WorkManager replacement
We already use Spring in the project so I'll have a look there. Thanks On 13 February 2015 at 05:29, Daniel Mikusa wrote: > On Thu, Feb 12, 2015 at 11:59 PM, Kevin Hale Boyes > wrote: > > > I currently have an application running on weblogic that I'm moving over > to > > tomcat 8. > > One of the things the application does is run background jobs using the > > commonj WorkManager. These jobs are managed by weblogic which seems to > be > > the recommended practice. > > > > What is the best/recommended way to run background jobs in Tomcat 8? > > > > Personally I'd use Spring, which has a nice and simple way to schedule > tasks. I'd also be using Spring for other things though and I'm not sure > I'd pull it in just for scheduled tasks. > > A quick google search came up with this library. > >http://commonj.myfoo.de/ > > Haven't personally used it though. > > I suppose another option would be to just use java.util.concurrent. > > Dan > > > > > > Thanks, > > Kevin > > >
Re: WorkManager replacement
On 2/13/2015 7:29 AM, Daniel Mikusa wrote: On Thu, Feb 12, 2015 at 11:59 PM, Kevin Hale Boyes wrote: I currently have an application running on weblogic that I'm moving over to tomcat 8. One of the things the application does is run background jobs using the commonj WorkManager. These jobs are managed by weblogic which seems to be the recommended practice. What is the best/recommended way to run background jobs in Tomcat 8? Personally I'd use Spring, which has a nice and simple way to schedule tasks. I'd also be using Spring for other things though and I'm not sure I'd pull it in just for scheduled tasks. I use java.util.timer for my scheduled jobs in tomcat. A quick google search came up with this library. http://commonj.myfoo.de/ Haven't personally used it though. I suppose another option would be to just use java.util.concurrent. Dan Thanks, Kevin - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: WorkManager replacement
On Thu, Feb 12, 2015 at 11:59 PM, Kevin Hale Boyes wrote: > I currently have an application running on weblogic that I'm moving over to > tomcat 8. > One of the things the application does is run background jobs using the > commonj WorkManager. These jobs are managed by weblogic which seems to be > the recommended practice. > > What is the best/recommended way to run background jobs in Tomcat 8? > Personally I'd use Spring, which has a nice and simple way to schedule tasks. I'd also be using Spring for other things though and I'm not sure I'd pull it in just for scheduled tasks. A quick google search came up with this library. http://commonj.myfoo.de/ Haven't personally used it though. I suppose another option would be to just use java.util.concurrent. Dan > > Thanks, > Kevin >
WorkManager replacement
I currently have an application running on weblogic that I'm moving over to tomcat 8. One of the things the application does is run background jobs using the commonj WorkManager. These jobs are managed by weblogic which seems to be the recommended practice. What is the best/recommended way to run background jobs in Tomcat 8? Thanks, Kevin