Yes, the isAnyTaskPending will not work correctly coz I need to grab a lock on this and then check whether each of the vectors/lists are empty or not. You're clearly seeing the issue, but the solution may not be quite there yet. If you grab a lock on
this, that won't prevent another
thread from calling addTask, etc, which will mess up your
test unless the odd inaccuracy doesn't matter that much. Everything would have to synchronize on
this, in which case you'd be better of using unsynchronized data structures.
You hit upon one of my pet peeves, actually. Developers over-use Hashtable and Vector in multi-threaded code "because they are threadsafe". Yes, they are threadsafe by themselves, but the code constructed around them usually ends up being very, very thread-
unsafe. Better start out using unsynchronized classes and be on your toes all the time.
- Peter