encyclopegia.org

Active object

The active object design pattern decouples method execution from method invocation for objects that each reside in their own thread of control. The goal is to introduce concurrency, by using asynchronous method invocation and a scheduler for handling requests. The pattern consists of six elements: * A proxy, which provides an interface towards clients with publicly accessible methods. * An interface which defines the method request on an active object. * A list of pending requests from clients. * A scheduler, which decides which request to execute next. * The implementation of the active object method. * A callback or variable for the client to receive the result.

The active object design pattern decouples method execution from method invocation for objects that each reside in their own thread of control. The goal is to introduce concurrency, by using asynchronous method invocation and a scheduler for handling requests. The pattern consists of six elements: A proxy, which provides an interface towards clients with publicly accessible methods. An interface which defines the method request on an active object. A list of pending requests from clients. A scheduler, which decides which request to execute next. The implementation of the active object method. A callback or variable for the client to receive the result. package org.wikipedia.examples; public class MyClass { private double val = 0.0; public void doSomething() { val = 1.0; } public void doSomethingElse() { val = 2.0; } } The class is dangerous in a multithreading scenario because both methods can be called simultaneously, so the value of val (which is not atomic—it's updated in multiple steps) could be undefined—a classic race condition. You can, of course, use synchronization to solve this problem, which in this trivial case is easy. But once the class becomes realistically complex, synchronization can become very difficult. To rewrite this class as an active object, you could do the following: package org.wikipedia.examples; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; public class MyActiveObject { private double val = 0.0; private BlockingQueue dispatchQueue = new LinkedBlockingQueue (); public MyActiveObject() { Thread t = new Thread(new Runnable() { @Override public void run() { try { while (true) { dispatchQueue.take().run(); } } catch (InterruptedException e) { // okay, just terminate the dispatcher } } }); t.start(); } public void doSomething() throws InterruptedException { dispatchQueue.put(new Runnable() { @Override public void run() { val = 1.0; } }); } public void doSomethingElse() throws InterruptedException { dispatchQueue.put(new Runnable() { @Override public void run() { val = 2.0; } }); } } Another example of active object pattern using Java 8 features. package org.wikipedia.examples; import java.util.concurrent.ForkJoinPool; public class MyClass { private double val; // container for tasks // decides which request to execute next // asyncMode=true means our worker thread processes its local task queue in the FIFO order // only single thread may modify internal state private final ForkJoinPool fj = new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); // implementation of active object method public void doSomething() throws InterruptedException { fj.execute(() -> { val = 1.0; }); } // implementation of active object method public void doSomethingElse() throws InterruptedException { fj.execute(() -> { val = 2.0; }); } } ==See also== Concurrent object-oriented programming Actor model Futures and promises Live distributed object ==References== ==External links== Ultra-high performance middleware based on Disruptor Active Object in C++14 Active Object implementation in C++11

References

No reference rows published for this article.

Cite this article

MLA

"Active object." encyclopegia.org, 2026, https://encyclopegia.org/wiki/active-object. Accessed 24 November 2026.

Chicago

"Active object." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/active-object.

APA

encyclopegia.org. (2026). Active object. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/active-object

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Dorota Kędzierzawska

enwiki · references available

Mark Potter (judge)

enwiki · references available

Neo Black Movement of Africa

enwiki · references available

Frederick Halterman

enwiki · references available

Chacon

enwiki · references available

Ligovka-Yamskaya Municipal Okrug

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1368481061 · 0.5 · snapshot enwiki-001368481061

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.