template < class C >

class Activity

Library: Foundation
Package: Threading
Header: Poco/Activity.h


This template class helps to implement active objects. An active object uses threads to decouple method execution from method invocation, or to perform tasks autonomously, without intervention of a caller.

An activity is a (typically longer running) method that executes within its own task. Activities can be started automatically (upon object construction) or manually at a later time. Activities can also be stopped at any time. However, to make stopping an activity work, the method implementing the activity has to check periodically whether it has been requested to stop, and if so, return. Activities are stopped before the object they belong to is destroyed. Methods implementing activities cannot have arguments or return values.

Activity objects are used as follows:

class ActiveObject
        _activity(this, &ActiveObject::runActivity)


    void runActivity()
        while (!_activity.isStopped())

    Activity<ActiveObject> _activity;


Direct Base Classes: Runnable

All Base Classes: Runnable

Member Summary

Member Functions: isRunning, isStopped, run, start, stop, wait

Inherited Functions: run



typedef typename RunnableAdapterType::Callback Callback;


typedef RunnableAdapter < C > RunnableAdapterType;


Activity inline

    C * pOwner,
    Callback method

Creates the activity. Call start() to start it.


~Activity virtual inline


Stops and destroys the activity.

Member Functions

isRunning inline

bool isRunning() const;

Returns true if the activity is running.

isStopped inline

bool isStopped() const;

Returns true if the activity has been requested to stop.

start inline

void start();

Starts the activity by acquiring a thread for it from the default thread pool.

stop inline

void stop();

Requests to stop the activity.

wait inline

void wait();

Waits for the activity to complete.

wait inline

void wait(
    long milliseconds

Waits the given interval for the activity to complete. An TimeoutException is thrown if the activity does not complete within the given interval.

run protected virtual inline

void run();

See also: Poco::Runnable::run()