klamath
12-12-2000, 01:17 PM
I'm writing a multi-threaded network daemon in Java. I'm still in the 'design' stage, but I can't figure out how to do a particular task. Here's the scenario:
I have a collection of cached data (probably in a HashMap, with 2 fields: the data, and a timestamp of when the data was last generated). Once in a while (lets say every 10 minutes), I want to spawn a thread which iterates through the items in the cache, and removes the old ones.
How do you do this? The main code of the daemon revolves around listening on a ServerSocket, and spawning threads to handle incoming connections. I'd rather not check the time on *every* incoming connection, because I'd like to handle hundreds of connections per second. Also, if I used something like this and there were no connections for 30 minutes, the maintainence stuff would not be done during that time. I could create the maintainence thread permanently and just get it to sleep() between use, but it would not be efficient to use an entire thread for this stuff, which is only done occaisonally and will only take 3 or 4 seconds to complete, at most.
Any ideas? Thanks in advance.
edit: Fix typos
------------------
- Klamath
Get my GnuPG Key Here (http://klamath.dyndns.org/mykey.asc)
Looking for an open source project to contribute to? Check out the Better Bulletin Board (http://bbb.sourceforge.net)
[This message has been edited by klamath (edited 12 December 2000).]
I have a collection of cached data (probably in a HashMap, with 2 fields: the data, and a timestamp of when the data was last generated). Once in a while (lets say every 10 minutes), I want to spawn a thread which iterates through the items in the cache, and removes the old ones.
How do you do this? The main code of the daemon revolves around listening on a ServerSocket, and spawning threads to handle incoming connections. I'd rather not check the time on *every* incoming connection, because I'd like to handle hundreds of connections per second. Also, if I used something like this and there were no connections for 30 minutes, the maintainence stuff would not be done during that time. I could create the maintainence thread permanently and just get it to sleep() between use, but it would not be efficient to use an entire thread for this stuff, which is only done occaisonally and will only take 3 or 4 seconds to complete, at most.
Any ideas? Thanks in advance.
edit: Fix typos
------------------
- Klamath
Get my GnuPG Key Here (http://klamath.dyndns.org/mykey.asc)
Looking for an open source project to contribute to? Check out the Better Bulletin Board (http://bbb.sourceforge.net)
[This message has been edited by klamath (edited 12 December 2000).]