beginners tutorial - Learn VB6
VB6 tutorial - Learn Advanced VB6
Analysis - System analysis and Design tutorial for Software Engineering
You are here: Visual
Basic > Advanced VB6 tutorial
> Chapter 12
Managing Threading in Out-of-Process Components
If your application is an out-of-process component (ActiveX EXE), you have three choices for its
threading model (refer to Figure 12.6):
A Single thread :- When a client makes a request to the component
before previous requests have finished processing, the additional request is serialized. A serialized
request is placed in a queue behind other requests on the same thread.
To make your out-of-process component single-threaded, select the Thread Pool option on the General
tab of the Project, Properties dialog box and make sure that the number of threads is one.
Typically, developers choose this option when compiling projects that were created in earlier
versions of VB.
Round-robin thread assignment to a fixed number of threads:- There
is an upper limit on the number of threads that the component will support. As additional
requests pile up beyond the maximum number of threads, the system moves to the next thread
(or cycles back to the first thread if it was already on the least thread), serializing
the new request behind other requests on the next thread.
To implement round-robin thread assignment, select the Thread Pool option on the General
tab of the Project, Properties dialog box, setting the number of threads to a number
greater than one. You must also make sure that the project is marked for Unattended
Round-robin threading can actually manage system resources and performance more efficiently
than can unlimited threading (discussed next), because round-robin threading limits the amount
of server overhead that will be dedicated to a COM component's objects.
The main disadvantage of round-robin threading is that it is nondeterministic regarding the
exact allocation of objects to threads. In other words, you can neither predict nor discover
which objects are assigned to which threads, nor whether threads are load balanced. Load
balancing is the art of allocating roughly similar amounts of work to available threads.
In other words, it is possible with round-robin threading that one thread might have half
a dozen objects serialized, and another thread may have only one object waiting in its queue,
or in some cases no object at all.
- Unlimited threads:- A separate new thread will begin for every new object.
To implement unlimited thread assignment, select the Thread per Object option on the General
tab of the Project, Properties dialog box. You must also make sure that the project is marked
for Unattended Execution.
Unlimited threads will, of course, guarantee that every new connection to the out-of-process
component gets its very own thread and therefore suffers no blockage.
The performance of the system as a whole might degrade with a lot of unlimited thread connections,
however, because the server will have to provide resources for each thread.
The section titled "Implementing Scalability Through Instancing and Threading Models"
discusses these threading options in the light of solution scalability.
NOTE - Single-Threaded ActiveX Controls Cause Problems
in Multithreaded Clients: If a client application is multithreaded, a
single-threaded ActiveX control can cause problems for the multithreaded client.
In fact, if a multithreaded client application is being written in VB, VB will
not even allow programmers to use a single-threaded ActiveX control in the project.
<< Previous | Contents
| Next >>