• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

ScheduledTimerTask - Period is not consistent

 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope I do not. Anything to do with few properties?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show your main class (the one with the main(String... args) method) ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BeForthrightWhenCrossPostingToOtherSites. (http://forum.springsource.org/showthread.php?p=308801)
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Web.xml

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Should I remove it from Context Loader Listner?


Yes
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic