java - Dispatching a task on a new thread, that can communicate with the parent thread -
i want dispatch task on new thread, , want task notify parent thread during various stages of execution. shown below:
void unzip(path source, path destination, observerthread observer) { int n = compute number of entries; observer.notify("n: " + n); while (there more entries) { observer.notify("unzipping " + name of entry); unzip entry; } observer.notify("done"); } what standard-library-only solution use case? (i want external dependencies.)
if you're using in swing should use swingworker (part of java). there's example on how publish interim results while doing work in background.
if you're not using swing standard java comes executors class. can create single thread executorservice , submit runnable it. not offer way of publishing results in progress can still callbacks manually show in example.
Comments
Post a Comment