Controls Threading Model

Overview

What threading issues exist when using and writing controls?

Controls default to a single-threaded model -- only one thread at a time will be executing code in a given control instance. This simplifies client and authoring logic, but may result in excessive contention and sub-optimal performance. Sophisticated control developers may choose to implement logic to handle multiple threads and concurrent execution.

Control Client

Client access to control instances (ie ControlBeans) is always thread-safe. Generated code + infrastructure manage concurrency issues:

Control Implementation

By default, control implementations delegate responsibility for thread-safety to the infrastructure, which provides a single-threaded environment for implementations. This is semantically equivalent to marking every operation and event handler method with "synchronized".

Implementations may choose to explicitly manage thread-safety issues themselves by annotating the implementation class with the @ThreadingModel annotation:

package org.apache.beehive.controls.api.bean;

public @interface ThreadingModel
{
    public enum Policy = { SINGLE_THREADED, MULTI_THREADED }
    public Policy value() default SINGLE_THREADED;
}

If an implementation specifies @ThreadingModel(ThreadingModel.Policy.MULTI_THREADED), the infrastructure will permit multiple threads to execute concurrently on operations and event handlers. The implementation is expected to use standard Java concurrency mechanisms to guarantee data coherency.

Open Issues

Controls/ControlsThreadingModel (last edited 2009-09-20 23:24:34 by localhost)