File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ScheduledTimerTask - Period is not consistent

 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange. After the fourth call, it looks like the period was been set to 10 seconds. You're not accessing the ScheduledTimerTask, are you ?
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope I do not. Anything to do with few properties?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show your main class (the one with the main(String... args) method) ?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:BeForthrightWhenCrossPostingToOtherSites. (http://forum.springsource.org/showthread.php?p=308801)


Yup. and I was about to give the link in my first thread.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Web.xml

 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
projectname-servlet.xml is loaded twice. Once by the DispatcherServlet, once by the ContextLoaderListener.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can not remove it from Dispatcher Servlet right?
Should I remove it from Context Loader Listner?

 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should I remove it from Context Loader Listner?

Yes
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic