Threading issues and component types

Each instance of a PowerBuilder component executes in its own session, and each session can support only one thread of execution. Therefore a single PowerBuilder component instance cannot simultaneously execute multiple client requests. However, multiple instances of the same component can each execute a separate client request. When you create a component, PowerBuilder sets default values for several properties that affect the way threads are handled in EAServer.

NoteUsing the Thread Manager You can also use the EAServer Thread Manager to develop more robust services. See “Using the EAServer Thread Manager”.

Concurrency property

The Concurrency property determines whether multiple instances of a component can be created to handle multiple client requests. Checking the Concurrency check box in the wizard or the Project painter sets the com.sybase.jaguar.component.thread.safe property to TRUE.

Standard components For standard components, you can improve performance by allowing multiple instances of a component to handle client requests. The default setting for the concurrency property for standard components is checked, but you can change the setting if you want only one instance of a given component.

Shared components For shared components, only one instance of the component should be active at any time and therefore only one thread can be executed. The Concurrency check box is disabled and not checked for shared components.

Service components Although service components are usually treated as shared components, you can choose to create more than one instance of a service component to improve performance and scalability. There are three options on the Components page that interact for service components: Concurrency, Automatic Demarcation/Deactivation, and Create Instances (the Create Instances option can be changed only for service components).

When you change the Create Instances option to 2 or more, the Concurrency check box and the Automatic Demarcation/Deactivation check box become checked. Multiple instances of the service component can be created if necessary, and are deactivated after each method call. If you clear the Automatic Demarcation/Deactivation check box, so that you need to explicitly deactivate component instances, the Create Instances check box is reset to 1 and the Concurrency check box is cleared.

bind.thread, sharing, and tx_vote properties

There are three other component properties that affect the handling of threads in EAServer: sharing, tx_vote, and bind.thread.

NoteBind Object property not used An additional property, bind.object, enables client threads to execute in a single instance but also supports creation of multiple instances. This property cannot be used for PowerBuilder components and is always set to FALSE.

When the bind.thread property is set to TRUE, a method on a component instance must execute on the same thread that created the instance. This property must be set to TRUE if you are using live editing to build your component. It should be set to FALSE for components that are deployed to UNIX servers to improve scalability.

The sharing property identifies whether or not the component is shared. It is set to FALSE when you select Standard in the wizard and to TRUE when you select Shared or Service. The only way this property can be changed in PowerBuilder is by changing the Create Instances setting on the Components tab page for service components in the Project painter. If either the sharing or thread.safe property is set to TRUE, the other must be set to FALSE.

A component that can remain active between consecutive method invocations is called a stateful component. A component that is deactivated after each method call and that supports instance pooling is said to be a stateless component. Typically, an application built with stateless components offers the greatest scalability. The tx_vote property determines whether the component is deactivated after every method call. It is set to FALSE (stateless) if you check the Automatic demarcation/deactivation check box in the wizard or select more than one instance on the Component page in the Project painter; otherwise it is set to TRUE (stateful). You can have only one instance of a stateful service object.

Table 24-1 summarizes the default setting for each type of component and shows which can be changed.

Table 24-1: Thread-handling properties

Component

bind.thread

sharing

thread.safe

tx_vote

Standard

FALSE, mutable

FALSE, immutable

TRUE, mutable

FALSE, mutable

Shared

FALSE, mutable

TRUE, immutable

FALSE, immutable

FALSE, mutable

Service (single instance)

FALSE, mutable

TRUE, immutable

FALSE, mutable

FALSE, mutable

Service (multiple instances)

FALSE, mutable

FALSE, immutable

TRUE, mutable

FALSE, mutable

If changed to TRUE, number of instances is set to 1, sharing to TRUE, and thread.safe to FALSE.

If you deploy a service component for which bind.thread, thread.safe, and sharing are set to TRUE, EAServer disables the thread.safe property automatically at runtime.