Synchronization question:
Set s = Collections.synchronizedSet(new HashSet());
private Object monitor_ = new Object();
//Set has element added in another routine...
//Called by some thread1, thread2, ...
TimerTask run(){ //method which executes every 1 min
synchronized(monitor_) {
s.isEmpty()
// ...
// waits for 30 seconds
// JNI call
// ...
}
}
//Called by cleanup thread
removecall()
{
synchronized( monitor_ ) {
s.remove( something );
}
}
Problem:
While TimerTask run method is executing the cleanup thread has to wait. Any efficient way
to handle this situation withut have to wait. e.g Re-entrant lock