• 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Java Util Timer Problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All ,
i have a problem with java.util.Timer Shcedule() that many threads accessing my Task and Abnormal behavior that it doesn't start at given start timer :

MyTimer Class :

output log :
2012-07-26 10:39:00,008 [Timer-6] INFO RefreshCacheTask.run(RefreshCacheTask.java:28) - *** Initializing Timer To Refresh CacheManager. - Current time Formatted: 26.07.2012 10:39:00
2012-07-26 10:39:00,008 [Timer-8] INFO RefreshCacheTask.run(RefreshCacheTask.java:28) - *** Initializing Timer To Refresh CacheManager. - Current time Formatted: 26.07.2012 10:39:00
2012-07-26 10:39:00,008 [Timer-7] INFO RefreshCacheTask.run(RefreshCacheTask.java:28) - *** Initializing Timer To Refresh CacheManager. - Current time Formatted: 26.07.2012 10:39:00
2012-07-26 10:39:00,009 [Timer-8] INFO RefreshCacheTask.run(RefreshCacheTask.java:29) - Refresh Cache Server Date [ Thu Jul 26 10:39:00 GMT+02:00 2012] Hour Is [10]
2012-07-26 10:39:00,008 [Timer-6] INFO RefreshCacheTask.run(RefreshCacheTask.java:29) - Refresh Cache Server Date [ Thu Jul 26 10:39:00 GMT+02:00 2012] Hour Is [10]
2012-07-26 10:39:00,009 [Timer-6] INFO RefreshCacheTask.run(RefreshCacheTask.java:30) - Refresh Cache Should Start at [15:00 AM]
2012-07-26 10:39:00,009 [Timer-8] INFO RefreshCacheTask.run(RefreshCacheTask.java:30) - Refresh Cache Should Start at [15:00 AM]
2012-07-26 10:39:00,009 [Timer-7] INFO RefreshCacheTask.run(RefreshCacheTask.java:29) - Refresh Cache Server Date [ Thu Jul 26 10:39:00 GMT+02:00 2012] Hour Is [10]
2012-07-26 10:39:00,010 [Timer-7] INFO RefreshCacheTask.run(RefreshCacheTask.java:30) - Refresh Cache Should Start at [15:00 AM]

please advice .
 
Saloon Keeper
Posts: 13366
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be more clear in what you think is going wrong. A bit of background on what you're trying to do and what's happening instead would be helpful. Try narrowing the problem down by creating an SSCCE, people are generally reluctant to look at log files and noise in code.

Welcome to CodeRanch!
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem to be invoking the overloaded schedule() method that accepts a TimerTask and two long aguments. I think you want the behaviour of the overloaded version that excepts a TimerTask, a Date and a long instead.
Have a look at the API documentation for java.util.Timer (<-click). Also note that if a lot of threads use the same Timer instance to schedule taks you can get in trouble fairly easily, as Timer is single-threaded.
A long running task can prevent other scheduled tasks from executing in a timely fashion and cause all sorts of unexpected / unwanted behaviour. Also, don't forget to cancel() the Timer if it's not running as a daemon.

Edit: Ack, ignore my statement above. I thought you were callding getTime() on a Date, but it was a Calendar.
 
Eng Mabdelnaby
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dears ,
thanks for your support but i rejected using timer with web application according to many issues appeared like that i made timers to refresh my cached settings from DB and if i redployed other EARs new timers generated and old timers still running and so on so i will not use Timers with J2EE application.

Thanks
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic