A method in a computer system for accessing Microsoft Component Object Model
("COM")
objects of varying thread types from a Java-based program. The computer system
has a Java virtual machine ("VM") that executes statements of the Java program
and that executes in a multithreaded process. When executing a statement of the
Java-based program to instantiate a COM object, the system creates a wrapper object.
When the COM object is not thread-safe, the system requests an appropriate thread
to instantiate the COM object and stores an identifier of the thread in the wrapper
object. When the COM object is thread-safe, the system instantiates the COM object
from the current thread and stores an indication in the wrapper object that the
COM object can be accessed from any thread. When executing a statement of the Java-based
program to invoke a method of the COM object, the system requests the thread identified
in the wrapper object to invoke the method of the COM object. When the wrapper
object indicates that the COM object can be referenced from any thread, the system
invokes the method of the COM object referenced by the wrapper object directly
from the current thread.