Methods Summary |
---|
public void | enter()
if ( DEBUG ){
debugEntry();
}
Thread current_thread = Thread.currentThread();
synchronized( this ){
entry_count++;
if ( owner == current_thread ){
nests++;
}else{
if ( dont_wait == 0 ){
try{
waiting++;
last_waiter = current_thread;
if ( waiting > 1 ){
// System.out.println( "AEMonitor: " + name + " contended" );
}
// we can get spurious wakeups (see Object javadoc) so we need to guard against
// their possibility
int spurious_count = 0;
while( true ){
wait();
if ( total_reserve == total_release ){
spurious_count++;
if ( spurious_count > 1024 ){
Debug.out( "AEMonitor: spurious wakeup limit exceeded" );
throw( new Throwable( "die die die" ));
}else{
Debug.out("AEMonitor: spurious wakeup, ignoring" );
}
}else{
break;
}
}
total_reserve++;
}catch( Throwable e ){
// we know here that someone's got a finally clause to do the
// balanced 'exit'. hence we should make it look as if we own it...
waiting--;
owner = current_thread;
Debug.out( "**** monitor interrupted ****" );
throw( new RuntimeException("AEMonitor:interrupted" ));
}finally{
last_waiter = null;
}
}else{
total_reserve++;
dont_wait--;
}
owner = current_thread;
}
}
|
public void | exit()
try{
synchronized( this ){
if ( nests > 0 ){
if ( DEBUG ){
if ( owner != Thread.currentThread()){
Debug.out( "nested exit but current thread not owner");
}
}
nests--;
}else{
owner = null;
total_release++;
if ( waiting != 0 ){
waiting--;
notify();
}else{
dont_wait++;
if ( dont_wait > 1 ){
Debug.out( "**** AEMonitor '" + name + "': multiple exit detected" );
}
}
}
}
}finally{
if ( DEBUG ){
debugExit();
}
}
|
public static java.util.Map | getSynchronisedMap(java.util.Map m)
return( Collections.synchronizedMap(m));
|
public boolean | hasWaiters()
synchronized( this ){
return( waiting > 0 );
}
|
public boolean | isHeld()
return( owner == Thread.currentThread());
|