Constantly running background class?
| |
I meant to say operation. I'm trying to make a program that does 2 things at once. More specifically, a bank account. On top of its regular classes to modify variables, it also has a hidden timer to calculate interest rates. Right now, the regular classes are built in gui mode, but I don't know how to constantly get the timer running. Currently, it checks the time after every action done in the gui if its time to add interest, but its very irregular, such as 4:12:26, 4:14:35, 4:15:06. If they freeze on a screen for like 6 minutes then do an action, it will look something like 4:35:22, 4:35:22, 4:35:22, 4:35:22, 4:35:22, 4:35:22, which isn't right. What I need it to do is something like 4:12:26, 4:13:26, 4:14:26, etc. Any help is appreciated. |
Re: Constantly running background class?
Link |
by
on 2010-05-25 14:58:58
|
This can be accomplished using Threads. http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html For the bank account project, use of Timers may be helpful. When using multiple threads, be sure to avoid unwanted Race Conditions! |