How do I simulate a buffered peripheral device with SwingWorker?

It may help to know that SwingWorker uses an ExecutorService internally; it adds the interim EDT processing mechanism for convenience. As long as you update your GUI on the EDT and synchronize access to any shared data, the latter is equivalent to the former.

Assuming you are using the Model–View–Controller pattern, suggested here, your model is the operation of a cpu. Although it may be a different class, I can’t see any reason to model the card reader on a different thread. Instead, let the processor model have a card reader model that does the waiting on a java.util.Timer thread, updating the model as the timer fires. Let the updated model notify the view in the normal course of posting events to the EDT. Let the controller cancel and schedule the card reader model in response to view gestures.

Leave a Comment