concept worker in category java

appears as: worker, worker, The worker
Griffon in Action

This is an excerpt from Manning's book Griffon in Action.

Making the worker do something

When the worker is ready to be executed, either by defining a true value for its start property or by calling its start() method directly, it will call the code defined by the work() pseudo-node. But as opposed to onInit(), the code defined for work() is guaranteed to run outside the EDT. The onDone() pseudo-node will be called once this one has finished doing whatever you instructed it to do.

Occasionally, you’ll want to refresh the UI contents with the partial results, and you need a way to get back into the EDT. Before you glance at the previous threading facilities, you should know that the SwingWorker’s designers took this scenario into account; thus there is a handy publish() method available. It signals the worker to process whatever parameters you send to the publish() method in the EDT; that’s the job of the third pseudo-node.

AspectJ in Action, Second Edition

This is an excerpt from Manning's book AspectJ in Action, Second Edition.

In this chapter, we’ll examine four design patterns: the worker object pattern, the wormhole pattern, the participant pattern, and the annotation-driven participant pattern. We’ll use AspectJ to illustrate each pattern. Except for the wormhole pattern, you can implement them using Spring AOP as well. In the chapters that follow, we’ll use these patterns for more advanced crosscutting implementations.

Runnable worker = new Runnable() {
    public void run() {
        ... invoke the work method
    }
}
... use the worker object:
    - send the worker object to a queue for execution,
    - or pass it to another subsystem for execution,
    - or simply call run() directly

In Java, a common implementation of a worker class implements Runnable, where the run() method invokes the worker method. When you execute such an object, it in turn executes the worker method. The worker object pattern offers a way to generate worker objects automatically for join points selected by a pointcut. You can then pass around these objects to implement various functionalities. When you use this pattern, you ensure a consistent behavior in your system—and you save a ton of code.