• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jconsole showing multiple java.util.Timer threads

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi....
I am using java.util.Timer in my code. I have two Timer. 1st runs after each 10 seconds and the other after each 6 hours. When I check the no. of threads in the jconsole its showing 4 threads for timer.
Actually I am not getting why its showing so. I dont want multiple threads for a single Timer to start as it can corrupt my data.
I have googled it a lot, as per my understanding it dosent start different threads to complete the tasks. It keeps the pending tasks in the queue.
But I am not getting why jconsole is showing it.
Please help me....

Thanks in advance.
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And does your code run correctly, i.e. does it do what you expect? If the answer is "Yes" then why are you concerned about that? If the answer is "No", however, then your strategy should be to look at your code and find the problem.
 
Mukesh Negi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even if its currently working correctly without any problem, in threading its not guarented in future, as i have coded considring 1 thread/timer. But if its wrong it may give unwanted result. I am using other apis i.e log4j for loging and c3p0 for connection pooling. I have found that c3p0 uses a timer. Thanks 4 your reply..
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest that you read java.util.Timer javadocs carefully. Espescially this part


Corresponding to each Timer object is a single background thread that is used to execute all of the timer's tasks, sequentially. Timer tasks should complete quickly. If a timer task takes excessive time to complete, it "hogs" the timer's task execution thread. This can, in turn, delay the execution of subsequent tasks, which may "bunch up" and execute in rapid succession when (and if) the offending task finally completes.

After the last live reference to a Timer object goes away and all outstanding tasks have completed execution, the timer's task execution thread terminates gracefully (and becomes subject to garbage collection). However, this can take arbitrarily long to occur. By default, the task execution thread does not run as a daemon thread, so it is capable of keeping an application from terminating. If a caller wants to terminate a timer's task execution thread rapidly, the caller should invoke the timer's cancel method.

 
Mukesh Negi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for all your replies. Actually, their were no issues. It is the C3P0 which makes a timer for each datasource object created and therefore I was getting extra Timer threads.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic