Couple of java SE programming questions

Magix

Weaksauce
Joined
Jul 27, 2012
Messages
109
PS! Very beginner here, so excuse the stupid questions :D

So I'm creating this appointment/alert desktop program. You can save appointments to a certain time, view them, and get notified when they are about to take place. Two questions.

1) I want to create a popup when an appointment is at its' deadline. The plan is to create a timer that runs a piece of code every minute, checking all todays appointments to see if the time matches on any of them. How intensive is this on the computer? It's basically a piece of code that would be executing itself every minute, 24/7.. Are there better ways to do this?

2) I'm trying to allow the user to check a box if they want the program to run on startup. I know startup can take place in the registry, or you can put a shortcut to the startup folder.. Haven't found any good code examples anywhere for this. Any help? : (
 
1) I want to create a popup when an appointment is at its' deadline. The plan is to create a timer that runs a piece of code every minute, checking all todays appointments to see if the time matches on any of them. How intensive is this on the computer? It's basically a piece of code that would be executing itself every minute, 24/7.. Are there better ways to do this?
Since you can calculate the time difference between now and the next alert, just set the timer to go off when that amount of time has passed.

2) I'm trying to allow the user to check a box if they want the program to run on startup. I know startup can take place in the registry, or you can put a shortcut to the startup folder.. Haven't found any good code examples anywhere for this.
It may help your Google-ing to specify when you want it to occur -- either on machine startup, or on user logon. Alternatively, you could make a batch file to startup the application, and setup a scheduled task that runs the batch file on user logon or machine startup (whichever is appropriate).
 
Since you can calculate the time difference between now and the next alert, just set the timer to go off when that amount of time has passed.

I'd also do this, however depending on the timer it may end early, so you need to see if you still have more time to sleep before its actually time.

Also make sure that whatever timer you use causes your program to go idle, and not busy-wait @ 100% cpu.

The api documentation for the timer you use should have this information.
 
You don't need to run code every minute you can can just use java.util.Timer and use the method allows you to specify an exact time (as opposed to an elapsed time) for a TimerTask to run.
 
Back
Top