Chapter 32: Using the Thread Manager  Using the Thread Manager

Chapter 32: Using the Thread Manager

About the Thread Manager

The Thread Manager allows you to run EAServer component instances in threads that execute independently of client method invocations. You can use threads spawned by the Thread Manager to perform any processing that must occur asynchronously with respect to user interaction. For example, you might have a component method that begins a lengthy file indexing operation. The method could call the Thread Manager to start the processing in a new thread, then return immediately.

The Thread Manager and service components

You can use the Thread Manager as an alternative to creating a service component to handle repetitive processing. You may find the Thread Manager interface allows more design flexibility. For example, you can suspend processing in services run by the Thread Manager, and you can start threads at any time rather than only at server start-up.

The Thread Manager is the recommended way to spawn threads in Java or C++ components. In C++, using the Thread Manager avoids system-level thread calls that may affect portability. In Java and C++, components running in the Thread Manager can make in-memory intercomponent calls, whereas components running in user-spawned threads must make intercomponent calls through the network.

You can use the Thread Manager and service components together. For example, you might code a simple service component that spawns threads in the start or run method, and stops them in the stop method.

PowerBuilder developers can use the Thread Manager to develop more robust services. Since PowerBuilder components cannot support sharing and concurrency, you cannot develop a service that can be stopped or refreshed without using the Thread Manager. In the services start or run method, spawn threads that do the service's processing. In the service's stop method, call the Thread Manager stop method to halt the threads. For more information, see the Application Techniques manual in the PowerBuilder documentation.

The Thread Manager and the message service

If you are using threads to implement a provider/consumer algorithm, or an asynchronous notification system, consider using the EAServer message service implementation described in Chapter 31, “Using the Message Service.” The message service provides a ready-made infrastructure for solving these classes of problems. The message service uses the Thread Manager in its own implementation.

Using the scheduling facilities provided by the message service, you can restrict background processing to a server’s off-peak hours. For example, you may have threads running that index the text content of a Web site. Using a scheduled component and the Thread Manager, you can suspend processing at the beginning of the server’s peak use period, then resume processing at the end. “Subscribing to scheduled messages” describes how to subscribe to scheduled topics in the message service.

Thread Manager interface documentation

This chapter briefly discusses how to use the Thread Manager methods. For reference documentation, see the generated HTML documentation for the CtsComponents::ThreadManager IDL interface. You can view this documentation in the html/ir subdirectory of your EAServer installation. Using a Web browser, load the URL:


Where host is your server’s host name, and port is the HTTP port number.

Copyright © 2005. Sybase Inc. All rights reserved. Using the Thread Manager