Contact Management App uses Java’s concurrency tools to ensure the user interface stays responsive during heavy operations like loading contacts, searching large lists, and exporting files. All background work runs off the Swing Event Dispatch Thread (EDT) and safely marshals results back to the UI usingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/efrain-svg/Potes_Freddy_ProgInterfacesG_U3/llms.txt
Use this file to discover all available pages before exploring further.
SwingUtilities.invokeLater().
Background operations overview
| Operation | Mechanism | EDT-safe update |
|---|---|---|
| Loading contacts on startup | SwingWorker | done() → refrescarTabla() |
| Real-time search/filter | SwingWorker with cancellation | invokeLater() → sorter.setRowFilter() |
| Duplicate validation | SwingWorker | invokeLater() → dialog or save |
| CSV export | ExecutorService (2-thread pool) | invokeLater() → dialog + re-enable buttons |
| Status notifications | ExecutorService (1-thread pool) | invokeLater() → lbl_estado.setText() |
Asynchronous search
Every keystroke in the search field triggerssolicitarBusquedaAsync(). This method:
- Increments an
AtomicIntegersequence counter (searchSeq) - Cancels any running
searchWorkerviacancel(true) - Creates a new
SwingWorkerthat builds aRowFilterin the background - In
done(), checks if the sequence number still matches — if not (user typed again), the result is discarded
logica_ventana.java
Duplicate validation
When you save or update a contact, the app validates for duplicates asynchronously:- The UI enters a “busy” state — all buttons and inputs are disabled
- A
SwingWorkerscans the contacts list for matching email or phone - On completion, the EDT is notified — either the save proceeds or an error dialog appears
- The UI returns to normal state
Shared state synchronization
Three synchronization mechanisms protect shared mutable state:contactosLock — protects the contacts list
contactosLock — protects the contacts list
A plain
Object used as a monitor. Any code that reads or modifies the contactos ArrayList must be wrapped in synchronized (contactosLock) { ... }. This includes adding, updating, removing, and iterating contacts.exportLock — prevents concurrent CSV writes
exportLock — prevents concurrent CSV writes
A plain
Object monitor wrapping the dao.exportarCsv() call. Since exports run in a thread pool, this lock ensures two concurrent exports cannot corrupt the same output file.editLock — prevents simultaneous edits
editLock — prevents simultaneous edits
A
ReentrantLock that is tryLock()-ed before any edit operation begins. If the lock is already held by another operation, the user sees a “Contact is being edited” message. The lock is released after the edit completes or is cancelled.UI busy state
AnAtomicInteger busyCount tracks the number of in-flight operations. When it is greater than zero:
- All action buttons (New, Update, Delete, Export CSV) are disabled
- All input fields (name, phone, email, category, search) are disabled
- The progress bar switches to indeterminate mode
busyCount drops back to zero, all controls are re-enabled in a single invokeLater() call.
All UI mutations — including re-enabling controls — happen exclusively on the EDT via
SwingUtilities.invokeLater(). Background threads never touch Swing components directly.