When using Visual Basic to create an out-of-process ActiveX server, you have more options to control how threads are created and used within your server application. You can select to have your application run with one of the following three thread assignment models:
Only one thread of execution so that it runs just like any ActiveX server application you have built using earlier versions of Visual Basic. This mode also allows you to compile ActiveX servers built using earlier versions of Visual Basic without modification.
A limited number of threads running in your application, with a round-robin assignment of thread to request. This can lead to an imbalance in the work load of individual threads, but controls the number of threads running on the machine.
Each external request receives a separate thread, which provides you no way to control the total number of threads running on the machine on which the application is running, potentially degrading machine performance.
Of these three thread assignment models, the middle one is the one that really requires a detailed explanation. When you specify a number of threads to be allowed in an out-of-process ActiveX server application - as requests are received for objects from other applications - the ActiveX server application assigns the first request received to thread 1, the second to thread 2, the third to thread 3, and so on. After all of the threads have been assigned to server requests, the application starts with thread 1 again, starting around the active threads again, as shown in Figure 23.8.
The round-robin thread assignment model, with five active threads servicing requests from four clients, pass each subsequent request to the next thread in the sequence.
This could easily end up with one client application having several different threads servicing the application’s various requests. It also means that any single thread in the Visual Basic ActiveX server application can have several different applications calling methods in the same thread. This requires you to take particular care when designing your out-of-process ActiveX server applications so that, if a particular thread has several different applications calling its various methods, any data received from any of these applications is not mixed with data from one of the other applications.
The other aspect of the round-robin method of assigning threads to requests is that it does not guarantee an even balance of requests to threads. If threads 1 and 2 are idle, and thread 2 is the last thread to be assigned to a request, thread 3 is the next thread assigned to a request, even though it might already be busy servicing three or four other requests.