com.sun.jini.jeri.internal.runtime
Class JvmLifeSupport

java.lang.Object
  extended by com.sun.jini.jeri.internal.runtime.JvmLifeSupport

public class JvmLifeSupport
extends Object

This class maintains a thread if necessary, in the wait state, to prevent the jvm shutting down while remote objects hold strong references in the DGC. This implementation is more about scalability than performance, when a jvm only has a small number of remote objects exported, blocking is not likely to cause a performance problem, access to keepAliveCount blocked. However with very large numbers of remote objects exported, in a dynamic environment, blocking is unlikely to be an issue, in this case the read locks will remain uncontended as the blocking write lock is only required as the number of exported object approach zero. If the thread is interrupted, it will pass away, regardless of the number of objects exported.

Since:
2.2.0
Author:
Peter Firmstone

Field Summary
private  java.util.concurrent.atomic.AtomicInteger keepAliveCount
          number of objects exported with keepAlive == true
private  Thread keeper
          thread to keep VM alive while keepAliveCount > 0
private  java.util.concurrent.locks.Lock rl
           
private  java.util.concurrent.locks.ReadWriteLock rwl
          lock guarding keepAliveCount and keeper
private  java.util.concurrent.locks.Lock wl
           
 
Constructor Summary
JvmLifeSupport()
           
 
Method Summary
private  void check()
           
(package private)  void decrementKeepAliveCount()
          Decrements the count of objects exported with keepAlive true, stopping the non-daemon thread if decremented to zero.
(package private)  void incrementKeepAliveCount()
          Increments the count of objects exported with keepAlive true, starting a non-daemon thread if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rwl

private final java.util.concurrent.locks.ReadWriteLock rwl
lock guarding keepAliveCount and keeper


rl

private final java.util.concurrent.locks.Lock rl

wl

private final java.util.concurrent.locks.Lock wl

keepAliveCount

private final java.util.concurrent.atomic.AtomicInteger keepAliveCount
number of objects exported with keepAlive == true


keeper

private volatile Thread keeper
thread to keep VM alive while keepAliveCount > 0

Constructor Detail

JvmLifeSupport

JvmLifeSupport()
Method Detail

incrementKeepAliveCount

void incrementKeepAliveCount()
Increments the count of objects exported with keepAlive true, starting a non-daemon thread if necessary. The old implementation contained in ObjectTable, used synchronization on a single lock for incrementing and decrementing to judge when an idle thread should be created or interrupted.


decrementKeepAliveCount

void decrementKeepAliveCount()
Decrements the count of objects exported with keepAlive true, stopping the non-daemon thread if decremented to zero.


check

private void check()


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.