Skip to content

How to use your own ThreadFactory with Agent Runner

Problem

You need to use a specific ThreadFactory to manage threads in your process and want to schedule Agrona Agents.

Solution

Within the AgentRunner constructor, specify the ThreadFactory.

Sample

1
2
3
4
5
6
7
8
void startWithMyThreadFactory(ThreadFactory factory)
{
    Agent agent = new MyAgent();
    AgentRunner myAgentRunner = new AgentRunner(idleStrategy,
            Throwable::printStackTrace,
            errorCounter, composite);
    AgentRunner.startOnThread(myAgentRunner, factory);
}

Discussion

This is useful when you have a custom ThreadFactory that manages threads in a way particular to your application, for example by pinning the thread to a CPU core.

See Also