au.com.swz.swttocom.swt
Class STCResourceManager

java.lang.Object
  extended by au.com.swz.swttocom.swt.STCResourceManager
All Implemented Interfaces:
java.lang.Runnable

public class STCResourceManager
extends java.lang.Object
implements java.lang.Runnable

The SWTtoCOM Resource Manager is resposible for releasing held COM interface references. When an automation object is finalised by the Java garbage collector the automation instance it references is registered with this class. The finalise method itself cannot be used to release references since it is often run in a background thread and the instances must be released by the SWT UI thread. This class registeres itself on a SWT timer and then periodically releases the COM interfaces using the SWT UI thread.

Author:
Mark Richter

Method Summary
 void AddObj(IDisposeableResource obj)
          Adds a new interface reference to the list of references that will be release at the next interval.
static STCResourceManager getInstance()
          Returns the singleton instance of this manager.
static int getReleaseInterval()
          Returns the current release interval.
 void run()
          Called by SWT to release all held COM interface references.
static void setReleaseInterval(int releaseInterval)
          Sets the current release interval.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static STCResourceManager getInstance()
Returns the singleton instance of this manager. The first call to this method will create the singleton and register it with SWT.

Returns:
the singleton instance of this manager.

run

public void run()
Called by SWT to release all held COM interface references.

Specified by:
run in interface java.lang.Runnable

AddObj

public void AddObj(IDisposeableResource obj)
Adds a new interface reference to the list of references that will be release at the next interval.

Parameters:
obj - the reference to be released.

getReleaseInterval

public static int getReleaseInterval()
Returns the current release interval. The release interval is the number of milliseconds between calls for which this manager will release COM interface references.


setReleaseInterval

public static void setReleaseInterval(int releaseInterval)
Sets the current release interval. The release interval is the number of milliseconds between calls for which this manager will release COM interface references. A negative or zero value indicates that resources will be released immediately. Be very careful using this since it may cause a significant perform degredation as the finalization process continually calls the SWT UI thread to release the COM interfaces.

Parameters:
releaseInterval - the new release interval.