Threading application design considerations

Threading needs to be considered both at build time and at run time. The application design considerations are described here, the build time requirements are described in Threading build time considerations.

Run time

The session initialize should be performed before any other threads have started. All threads should finish before the session terminate is called; this includes all threads that might be involved in callback style operations.

Due to the underlying Java VM, the same threading model needs to be used in the application. In the case of the Sun and IBM JDKs this means that native Win32 threads should be used. In addition these JDKs used the MSVCRT C Runtime library, and this should be used in the application.

When a new thread wishes to access any WebSphere MQ Everyplace API function it must call the threadAttach function (found in the session API). When the thread has finished using the WebSphere MQ Everyplace API ( this could be well before the thread terminates) it should call the threadDetach function.

Failure to call the threadDetach function prior to the thread terminated (either naturally or forced) results in the system being put into an unstable state. This could result in premature failure.

Notes:

  1. If the number of calls to threadAttach and threadDetach do not match, sessionTerminate does not complete successfully.

  2. Do not call threadAttach multiple times on the same thread without calling theadDetach first. There is no restriction on calling multiple threadAttach/threadDetach pairs. Depending on the nature of your application it may be profitable to call theadDetach if your thread is going to do significant non-WebSphere MQ Everyplace work. Profiling of the particular application is recommend to determine whether this is worthwhile.


© IBM Corporation 2002. All Rights Reserved