posted 15 years ago
Well, if you want to have a thread safe implementation for your scenario, here's one I can suggest -
Have a SerialiserThread class. Something like this -
The AtomicBoolean takes care that the boolean value gets updated atomically in a multi-threaded environment.
Have a driver class which handles all the incoming threads requesting for SerializeObjects.
Currently, this driver class will make other threads wait indefinitely for another thread which is busy with the SerializeObject class, so you might want to put in a logic for having a timed wait using join(), or sleep() methods.
There can be some other ways to achieve this as well. Some might even be better. But for now, you can probably give this method a try.