In my previous entry, I presented the Indian Train Anti-Pattern, where we add without discrimination data to handle on our queues, leading to overcrowded queues.
For instance, we do not wish to add to our queue an event telling us that data was not modified. Another example would be to send an event to our UI to notify of a data change for an item that is not even visible on the screen. We can imagine a large table with 10000 lines, but only 100 of them are displayed at a time.
public class Display {
public void show(Data data) {
Data prevData = getPrevData(data);
if (data.equals(prevData)) return;
if (!isDisplayed(data)) return;
SwingUtilities.invokeLater(() -> table.updateRow(data));
}
}
This is one way to reduce the size of the queue: drop some of the events. Next time we’ll see another way: the Hamburger Pattern. Stay tuned!
No comments:
Post a Comment