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....
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.
Joined: Jul 25, 2012
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..
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.
Joined: Jul 25, 2012
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.