Microsoft SDK for Java

threadStartMTA

Deprecated and replaced by startMTAThread. If you use threadStartMTA and use J/Direct to call CoInitializeEx, the VM detects this and tags the thread as being inside the MTA to allow proper marshaling.

This method of the ComLib Class initializes a thread without initializing COM. This means that the thread's run method must explicitly initialize COM as single-threaded or multi-threaded apartment, using J/Direct to call CoInitializeEx, as demonstrated below:

import com.ms.com.*;
public class RunInMTA implements Runnable
{
    /** @dll.import("ole32", auto) */
    private static native void CoInitializeEx(int pvReserved, int flags);
    /** @dll.import("ole32", auto) */
    private static native void CoUninitialize();
    private static final int COINIT_MULTITHREADED = 0;
    public void run() {
        CoInitializeEx(0, COINIT_MULTITHREADED);
        //  Do work.
        CoUninitialize();
    }
    public static void main(String args[]) {
        Thread t = new Thread(new RunInMTA());
        ComLib.threadStartMTA(t);
    }
}

This method is similar to the Thread.start method, but Thread.start initializes the thread as a separate single-threaded COM apartment.

Syntax

public static native void threadStartMTA(Thread thd);

Parameters

thd The Thread to start.

Exceptions

IllegalThreadStateException if the thread was already started.

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