foxtrot
Class ConcurrentWorker
java.lang.Object
foxtrot.ConcurrentWorker
public class ConcurrentWorker
- extends Object
The class that execute time-consuming Tasks and Jobs, but differently
from Worker, execute them concurrently and not one after the other, though
the invocations to post(Task) or post(Job) will finish one after
the other.
Most of the times, the best choice for having synchronous behavior is Worker,
so please think twice before using this class.
A typical usage of this class is, for example, in an application that needs to
communicate to a server to submit tasks and to cancel them.
Submitting a task to the server requires an event from the user, event1 - for
example clicking on a submit button, which will call ConcurrentWorker.post()
to submit the task task1 to the server in thread1.
If then the user wants to cancel task1, it generates a new event, event2 -
for example clicking on a cancel button, which will call ConcurrentWorker.post()
to submit a task task2 to the server in thread2 that will cancel
task1.
However, since event2 is dequeued by Foxtrot during the execution of task1,
the first invocation of ConcurrentWorker.post() (the one that submitted the
task to the server) does not return until event2 and hence the second invocation
of ConcurrentWorker.post() is finished.
Therefore, this class will execute tasks concurrently, but invocations of
ConcurrentWorker.post() are executed one after the other.
This ensures that the code after the second invocation of
ConcurrentWorker.post() is always executed before the code after the first
invocation of ConcurrentWorker.post() (this is not guaranteed when
using AsyncWorker).
Using Worker would make it impossible to cancel the task, since task2 will
be executed only when task1 is finished.
Needless to say, this concurrent behavior imposes further care in designing the
system to respect thread safety, and to keep the system simple to understand.
- Version:
- $Revision: 260 $
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
getWorkerThread
public static WorkerThread getWorkerThread()
- See Also:
Worker.getWorkerThread()
setWorkerThread
public static void setWorkerThread(WorkerThread workerThread)
- See Also:
Worker.setWorkerThread(foxtrot.WorkerThread)
getEventPump
public static EventPump getEventPump()
- See Also:
Worker.getEventPump()
setEventPump
public static void setEventPump(EventPump eventPump)
- See Also:
Worker.setEventPump(EventPump)
post
public static Object post(Task task)
throws Exception
- Throws:
Exception- See Also:
Worker.post(Task),
post(Job)
post
public static Object post(Job job)
- See Also:
Worker.post(Job),
post(Task)
Copyright © 2011 KnowledgePlaza. All Rights Reserved.