• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Util Timer Problem  RSS feed

 
Eng Mabdelnaby
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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 .
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • 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!
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!