Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Setting a timer in my program  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have a program that I would like to run every hour. All the code I need is in Email.Run() which I execute in the main. Looking online I found a solution that I pieced together for a timer. My problem is that my program will accumulate an enormous amount of memory and CPU after about 30-45 minutes of running. I've been looking into garbage collection and haven't found much help there, besides that the system should do it all on its own. I've heard that the library Timer is a bit outdated? I'm starting here because I don't think there's a problem with how my Run() method performs. I think the main method is performing too many behind the scene "checks" of the time maybe. I don't see anything wrong with my code but can anyone provide any insight or other coding techniques to perform this every hour method?I also looked into threading but I want to know if that would be the solution or not. I would still need to include a timer in the thread and I think that maybe that's where my logic is going wrong.


Thank you
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see anything in that code that would be a huge CPU or memory hog. Presumably it's in your Email.Run() method (which should be named run(), but the way--by convention, method names start with a lowercase letter), but without seeing it, it's impossible to say.

And even if we could see it, any suggestions would probably be just guesses. The proper way to diagnose memory and CPU bloat is not by staring at code and guessing, but by using a profiler.
 
Joe Niksa
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is what I just started doing in Netbeans. Good call on the convention also. I'll see if I can tinker with it more and come up with something after some monitoring.
Thanks
 
Marshal
Posts: 60803
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Niksa wrote: . . .//this is the method you should use, not the Date(), because it is desperated. . . .

Does that mean deprecated?
 
Joe Niksa
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ha, yes definitely deprecated. I must have been really tired writing that comment
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!