This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Spring and the fly likes ScheduledTimerTask - Period is not consistent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "ScheduledTimerTask - Period is not consistent" Watch "ScheduledTimerTask - Period is not consistent" New topic
Author

ScheduledTimerTask - Period is not consistent

Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374


The run() method contains only logger statement as I just want to confirm it executes or not.

Here is the output,



Why the period between two successive execution does not remain consistent (20 second that I have declared)?

Cross Post : http://forum.springsource.org/showthread.php?t=91991
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Strange. After the fourth call, it looks like the period was been set to 10 seconds. You're not accessing the ScheduledTimerTask, are you ?


[My Blog]
All roads lead to JavaRanch
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Nope I do not. Anything to do with few properties?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Can you show your main class (the one with the main(String... args) method) ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

BeForthrightWhenCrossPostingToOtherSites. (http://forum.springsource.org/showthread.php?p=308801)
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
It's a web app. So through dependency injection it stats the timer. And it executes the run method of CSVTimerTask class. CSVTimerTask class requires to extends TimerTask.

To be precise , I have used Spring reference documentation. Spring 2.5.6 . http://static.springsource.org/spring/docs/2.5.x/reference/scheduling.html#scheduling-jdk-timer

Thanks for your time.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374


Yup. and I was about to give the link in my first thread.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Thinking about it again, it seems that there are two timers running here. I wonder if you're loading your context file twice ? Please show your web.xml.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Web.xml

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

projectname-servlet.xml is loaded twice. Once by the DispatcherServlet, once by the ContextLoaderListener.
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
I can not remove it from Dispatcher Servlet right?
Should I remove it from Context Loader Listner?

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Should I remove it from Context Loader Listner?

Yes
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Christophe Verré wrote:
Should I remove it from Context Loader Listner?

Yes


This leads me to another issue.
,


The reason behind this error is , I have declared this bean in projectname-servlet.xml file. Now as I have remove it from contextConfigLocation, it executes next file which is projectname-customer.xml file. and this file uses FacadeLookup . so obviously it will throw above error.

My questions are,
1) How to resolve this issue?
2) Should not projectname-servlet.xml execute very first and others after that as it is main xml file?
3) How ContextLoaderListener uses value of contextConfigLocation (application wide param)?

Thank you for your time.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

1)Make a new context file, move everything you can from projectname-servlet.xml into it, except the scheduler.
2)In a web application, listeners are instanciated before servlets. It's not just Spring.
3)Check the org.springframework.web.context.ContextLoader API
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ScheduledTimerTask - Period is not consistent