Forgive me for posting this here but that Threads and Synchronization forum just doesn't get as much traffic
This is in reference to this tutorial:
Using the notifyAll and wait Methods I have 3
synchronized functions that do the following (
simplified for everyone's sake):
generateKey()- generates a Key object that stores 2 Date timestamps- the time of creation and expiration (ie. 10 mins. later) respectively- along with a
String representing the key value. This object gets placed into a private member HashTable. I originally used HashMap but the synchronization issues led me to change to a HashTable
isValidKey(String checkMe)- obtains the Key object from the HashTable corresponding to the hashkey "checkMe" and checks if the expiration time has passed.
removeExpiredKeys()- Get's called by the run() function every 60 minutes and removes keys that are expired. This is pseudo-code to make it easier to read.
The run function looks like this:
From my main() I simply create
one thread and let run() take care of everything. The functions generateKey and isValidKey are called from other classes at undetermined times. Worst case we've got thousands of calls to generateKey and isValidKey a minute.
After all of that, my question is Do I have to use wait() and notifyAll() like the tutorial states? Or because I'm using wait(long time) and not wait() I shouldn't be worried. The variable "hashTable" is the object that I want to ensure is synchronized between all those functions.
Thanks guys. I appreciate it.