Microsoft SDK for Java

Instantiating New COM Objects

When a Java class representing a COM object is instantiated using new, the Microsoft VM obtains the COM object's threading model from the registry. What happens next depends on which threading model is in effect.

For the Both or Free threading models, the object is assumed to be thread-safe and is instantiated on the calling thread. Any method call on this object will translate directly to a method call on the underlying COM object on the calling thread.

For the single threading model, the Microsoft VM automatically marshals to the process's main apartment thread to create the object. Furthermore, it marshals all method calls on this object back to the main apartment thread. This represents the @com directive's additional overhead, but this is required for non–thread-safe objects.

For the apartment threading model, the Microsoft VM similarly marshals the object creation and method calls. If the creating thread is considered apartment-hostable, the object is created on that thread. Otherwise, the Microsoft VM automatically creates an apartment thread, and the object is created on that thread. All objects created this way share one special apartment thread. The Microsoft VM does not create a new thread for every object.

© 1999 Microsoft Corporation. All rights reserved. Terms of use.