• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why does the run method in timertask executed twice  RSS feed

 
Lynnhom Hsueh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I encountered a problem very similar described here :http://www.experts-exchange.com/Programming/Languages/Java/Q_22157484.html
I also tried the thread sleep method. It gets the same result.
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lynnhom,Welcome to javaranch....
Things go unexpectedly wrong when you provide links in your posts casting your real problems in the problems and solutions described in those links instead of describing your original problem here at JavaRanch.... .
Try to google things but on javaranch describe your problems in your way rather than providing links here.
By the way your problem seem to be related to the tasks which should be executed at fixed intervals of time starting after specified amount of time.
Check the sample code given below-



For me this code prints "Hiiiii" after 50 seconds first time and then prints same after every 60 seconds.You can put your own business logic instead of System.out.println("hiiiii"); here.
Now tell me what you have done and what useful you have found in give code snippet.
 
Lynnhom Hsueh
Greenhorn
Posts: 2
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit, Thank you for your quick reply!
Let me describe my problem more specific: I want to make a Email auto sending function in my Red5 project. And I create a timer and schedule a timer task in the constructor of my Main Application class.
And I have found the reason now.
The constructor of Main Application has been executed twice.
Anyway, Thank you for your kindness again!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!