How to create multiple StreamBase-managed threads in an adapter or operator

How to create multiple StreamBase-managed threads in an adapter or operator

book

Article ID: KB0076357

calendar_today

Updated On:

Products Versions
TIBCO Streaming -

Description

How to create multiple threads in an adapter or operator that work with Streambase's thread control.

Issue/Introduction

How to create multiple StreamBase-managed threads in an adapter or operator

Resolution

In Operator.init() call registerRunnable(object) on any class implementing Operator and with a run() method. For a single thread, we often implement run() in the main adapter class and call registerRunnable(this,...), but it may be called for any object that needs its own thread.

The thread created by registerRunnable() should have a while(shouldRun()) loop and shouldRun() needs to be checked frequently and shortly after registerRunnable() is called, so limit the amount of setup needed between calling registerRunnable() and shouldRun() the first time into the loop.