![]() |
The ActiveX to EJB bridge supports both free-threaded and apartment-threaded access and implements the Free Threaded Marshaler to work in a hybrid environment such as Active Server Pages. Each thread that is created in the ActiveX process will be mirrored in the Java environment when the thread communicates through the ActiveX to EJB bridge. In addition, once all references to Java objects (there are no JObjectProxy or JClassProxy objects) in a ActiveX thread, the ActiveX to EJB bridge will detach the thread from the JVM. Therefore, you must be careful that any Java code that you access from a multi-threaded Windows application is thread-safe. Visual Basic and VBScript applications are both essentially single-threaded. Therefore, Visual Basic and VBScript applications don't really need to worry about threading issues in the Java programs they access. Active Server Pages and multi-threaded C and C++ programs do need to worry.
Consider the following scenario:
ActiveX Process | JVM Access by ActiveX Process |
---|---|
Thread A - Created in 1 | Thread 1 - Attached in 2 |
Thread B - Created in 4 | Thread 2 - Attached in 4, detached in 6 Thread 3 - Attached in 7 |
Thread C - Created in 4 |
Threads and Active Server Pages
Active Server Pages in Microsoft's Internet Information Server is a multi-threaded environment. When you create the XJB.JClassFactory object, you can store it in the Application collection as an Application-global object. This allows all threads within your ASP environment to access the same ActiveX to EJB bridge object. Active Server Pages by default creates 10 Apartment Threads per ASP process per CPU. This means that when your ActiveX to EJB bridge object is initialized it can be called by any of the 10 threads, not just the thread who created it.
If you need to simulate single-apartment behavior, you can create a Single-Apartment Threaded ActiveX DLL in Visual Basic and encapsulate the ActiveX to EJB bridge object there. This guarantees that all access to the JVM uses the same thread. You need to use the <OBJECT> tag to assign the XJB.JClassFactory to an Application object and must be aware of the consequences of introducing single-threaded behavior to a Web application.
The Microsoft KnowlegeBase has several articles about ASP and threads, including:
Related concepts... | |
How ActiveX programs use the ActiveX to EJB bridge | |
ActiveX to EJB bridge, calling Java methods | |
ActiveX to EJB bridge, good programming guidelines | |