Class SwingWorker<T,V>
- All Implemented Interfaces:
Runnable, Future<T>, RunnableFuture<T>
SwingWorker. Emulator-only per D_timer_swingworker — no
surrogate (SwingWorker isn't a Component).
Backed by a per-session pool of the JDK's own shape — ten daemon
platform threads over a LinkedBlockingQueue — so an eleventh
concurrent worker queues exactly as it does on the desktop
(D_worker_platform_threads). Lazy-attached on first execute(),
disposed when the session is destroyed (interrupts running workers).
EDT routing: publish(Object[]), process(List),
done(), and PCE fires hop from the worker thread to the
session's live UI via EHelper.onSessionLiveUI(VaadinSession, Runnable), which
resolves the current UI and enters EHelper.callSwing(Runnable),
so user callbacks see the same UI.getCurrent() + virtual-thread
envelope as any other Swing-side event handler (R_callswing_envelope). PCE fires raised
from the EDT itself bypass the hop and run inline (fast path + matches
Swing's synchronous PCE-on-EDT delivery).
get() and get(long, TimeUnit) called from the EDT
throw IllegalStateException per D_gap_severity_triage case 1 (loom rescue
trigger): real Swing deadlocks; we fail-fast with a message naming
the cause, preserving the migrator's mental model.
A EmulatorContext — the owning VaadinSession plus
the user's browser time zone — is captured at construction (not the UI), so
an in-flight worker survives an F5 @PreserveOnRefresh teleport and
delivers done()/process() onto the UI that is live at
completion time, not the (closed) one it started under. See
UiScopedFeaturesF5Test. Constructing with no current session throws
IllegalStateException. doInBackground() runs inside
EmulatorContext.call(Callable), so SimpleDateFormat / the
Calendar emulator format in the user's zone off the EDT rather than the
server default.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface Future
Future.State -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidfinal voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener) final booleancancel(boolean mayInterruptIfRunning) Cancels the worker.protected abstract TBackground work.protected voiddone()EDT-side callback afterdoInBackground()returns (success, exception, or cancel).final voidexecute()Submits this worker to the per-UI VT executor.final voidfirePropertyChange(String propertyName, Object oldValue, Object newValue) Fires a PropertyChangeEvent.final Tget()Blocks until the worker completes; returns its result.final Tfinal intfinal PropertyChangeSupportfinal SwingWorker.StateValuegetState()final booleanfinal booleanisDone()protected voidEDT-side callback for chunks published viapublish(Object[]).protected final voidCoalescing publish.final voidfinal voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener) final voidrun()Worker body.protected final voidsetProgress(int progress) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Future
exceptionNow, resultNow, state
-
Field Details
-
STATE_PROPERTY
- See Also:
-
PROGRESS_PROPERTY
- See Also:
-
-
Constructor Details
-
SwingWorker
protected SwingWorker()- Throws:
IllegalStateException- if no current Vaadin session — SwingWorkers are bound to the session they were constructed in.
-
-
Method Details
-
doInBackground
-
process
EDT-side callback for chunks published viapublish(Object[]). Default no-op. -
done
protected void done()EDT-side callback afterdoInBackground()returns (success, exception, or cancel). Default no-op. -
execute
public final void execute()Submits this worker to the per-UI VT executor. Idempotent — second and subsequent calls are no-ops (matches JDK contract: a worker may only be executed once). -
run
public final void run()Worker body. Drives the state machine: PENDING → STARTED → run doInBackground → DONE → schedule done() on EDT. The finally-block always finalises, so a throwndoInBackgroundstill transitions to DONE and fires done() (matches JDK).- Specified by:
runin interfaceRunnable- Specified by:
runin interfaceRunnableFuture<T>
-
cancel
public final boolean cancel(boolean mayInterruptIfRunning) Cancels the worker. IfmayInterruptIfRunningis true and a doInBackground is in flight, the worker thread is interrupted — doInBackground's I/O calls or sleeps seeInterruptedException. Returns true unless the worker had already completed. -
isDone
-
isCancelled
public final boolean isCancelled()- Specified by:
isCancelledin interfaceFuture<T>
-
getState
-
get
Blocks until the worker completes; returns its result.Allowed from the EDT only when
isDone()— that's the canonicaldone()call site, where the worker's already finished andget()returns immediately without blocking. ThrowsIllegalStateExceptionif called from the EDT before the worker finishes (D_gap_severity_triage case 1 loom rescue: under Swing this would deadlock the EDT).- Specified by:
getin interfaceFuture<T>- Throws:
IllegalStateException- if called from the EDT before the worker is done.InterruptedExceptionExecutionException
-
get
public final T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
getin interfaceFuture<T>- Throws:
IllegalStateException- if called from the EDT before the worker is done (D_gap_severity_triage case 1).TimeoutException- if the wait elapses without completion.InterruptedExceptionExecutionException
-
publish
Coalescing publish. Appends chunks to a pending list; the first publish since the last drain schedules one EDT-sideprocess(List)call that drains and clears the list. Subsequent publishes before the drain merge into the snapshot the scheduled process(...) will see. -
setProgress
protected final void setProgress(int progress) - Throws:
IllegalArgumentException- ifprogressis outside[0, 100](JDK-faithful).
-
getProgress
public final int getProgress() -
firePropertyChange
Fires a PropertyChangeEvent. On-EDT callers fire synchronously (matches Swing's same-thread PCE delivery); off-EDT callers hop viaEHelper.onSessionLiveUI(VaadinSession, Runnable)so listeners always run under the session's live UI lock inside aEHelper.callSwing(Runnable)VT continuation (R_callswing_envelope). -
getPropertyChangeSupport
-
addPropertyChangeListener
-
removePropertyChangeListener
-
addPropertyChangeListener
-
removePropertyChangeListener
public final void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
-