[josm-dev] downloading referrers and incomplete relation members from a script

Paul Hartmann phaaurlt at googlemail.com
Tue Oct 4 17:08:42 BST 2011


On 10/04/2011 07:21 AM, Jo wrote:
> And it works... asynchronously. If I use this code in a larger script, the
> code following it gets executed before the download is ready. This, of
> course, creates problems since the rest of the code depends on what was
> being downloaded.
> 
> Is there a way to make it wait? I've been trying countless scenarios All to
> no avail.

You can try something like this:

Main.worker.submit(new Runnable() {
    public void run() {
	// all code that depends on the
        // downloaded referrers goes here
    }
});

If this does not work, try wrapping it further in

SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        ...
    }
});

or the other way around, possibly multiple times (alternating).

Basically you have two threads, one is for network IO and expensive
calculations (worker) and the other for the GUI and lightweight stuff
(EDT). The script runs in EDT and
DownloadReferrersAction.downloadReferrers(...) schedules a task for the
worker. Both threads have a list of tasks that are processed in
sequence, so the DownloadReferrersTask should be finished, when the
worker thread works off the next task from the list.

Hope this helps, the code isn't really written with quick and dirty
scripts in mind.

Paul



More information about the josm-dev mailing list