1

I need some assistance in implementing a scheduler which runs parallel with the other processing. I found quartz scheduler for many of my searches on the web. But, I need something which is inbuilt and can run concurrently with other processes and not any external libraries

I checked with scheduleAtFixedRate. But, this has not option for parallel execution.

Can anyone please suggest in this regard?? My requirement is that, a java function has to run at every fixed intervals soon after the server starts. This will be known by the servlet start and I will have to initiate the scheduler in the init().

Pavan Kumar
  • 463
  • 2
  • 10
  • 18
  • What exactly do mean with "parallel execution"? Executors can be configured to do that, AFAIK. – Fildor Jan 21 '14 at 08:40
  • 1
    You're talking about Servlets so I guess you're somewhat using JEE. Why not using the EJB timer service ? http://docs.oracle.com/javaee/7/tutorial/doc/ejb-basicexamples004.htm – thomas.g Jan 21 '14 at 08:54

2 Answers2

4

My requirement is that, a java function has to run at every fixed intervals soon after the server starts

Ankur Shanbhag
  • 7,746
  • 2
  • 28
  • 38
  • Hi, 1. Can concurrency happen using `java.util.timer` ? 2. I do not wish to use any external libraries in my source and so quartz is not an option certainly. 3. I checked for it. As, I have mentioned in the question itself.. – Pavan Kumar Jan 21 '14 at 09:32
  • 1
    Yes, Timer will spawn a new thread (which executes concurrently). I have mentioned quartz just an additional option, depending on requirements. If you do not have such requirements go for executor or timer. – Ankur Shanbhag Jan 21 '14 at 09:43
  • Can you please elaborate more on timers?? Need some examples, which I'm not finding enough on the web. – Pavan Kumar Jan 21 '14 at 10:20
  • @PavanKumar : Please refer usage link provided in my post. It has basic example of timer usage. – Ankur Shanbhag Jan 21 '14 at 11:07
0

I suggest you to define a ServletContextListener, and to start a Quartz scheduler from its contextInitialized method.

contextInitialized is called on application deployment/reload on your application server, thus your scheduler can be initialized soon after the server starts.

ssssteffff
  • 964
  • 4
  • 16
  • I do not wish to use any external libraries in this case. Can you please suggest me something inbuilt in Java and can be used for my requirement?? – Pavan Kumar Jan 21 '14 at 09:35