[josm-dev] [PATCH] Make start-up feel faster by asynchronously loading the MOTD.

Petr Nejedly Petr.Nejedly at Sun.COM
Mon Nov 17 21:56:19 GMT 2008


Michel Marti napsal(a):
> Since loading and parsing the MOTD from the wiki now takes place
> in a separate thread, the main GUI will be ready for action (much)
> earlier (especially on slow network links).
> 
> Signed-off-by: Michel Marti <mcdmx at users.sf.net>
> ---
>  src/org/openstreetmap/josm/gui/GettingStarted.java |   15 ++++++++++++---
>  1 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/src/org/openstreetmap/josm/gui/GettingStarted.java b/src/org/openstreetmap/josm/gui/GettingStarted.java
> index 7174aeb..ae4ea86 100644
> --- a/src/org/openstreetmap/josm/gui/GettingStarted.java
> +++ b/src/org/openstreetmap/josm/gui/GettingStarted.java
> @@ -134,11 +134,20 @@ public class GettingStarted extends JPanel {
>      
>      public GettingStarted() {
>          super(new BorderLayout());
> -        assignContent();
> -                                
> +        final LinkGeneral lg = new LinkGeneral(tr("Loading MOTD..."));
> +        JScrollPane scroller = new JScrollPane(lg);
> +        // Asynchronously get MOTD to speed-up JOSM startup
> +        Thread t = new Thread(new Runnable() {
> +            public void run() {
> +                assignContent();

Don't dare to call live swing components from other threads.
JOSM usually use PleaseWaitRunnable, but it might not fit in here.
You'd also better use Main.worker instead of private thread, but
that's questionable - wiki might be unresponsive and you don't want
to block the user e.g. from downloading....

> +                lg.setText(content);
> +            }
> +        }, "MOTD-Loader");
> +        t.setDaemon(true);
> +        t.start();
> +
>          // panel.add(GBC.glue(0,1), GBC.eol());
>          //panel.setMinimumSize(new Dimension(400, 600));
> -        JScrollPane scroller = new JScrollPane(new LinkGeneral(content));
>          scroller.setViewportBorder(new EmptyBorder(10,100,10,100));
>          add(scroller, BorderLayout.CENTER);
>      }


-- 
Petr "Nenik" Nejedly, NetBeans/Sun Microsystems, http://www.netbeans.org
355/113 -- Not the famous irrational number PI, but an incredible simulation!




More information about the josm-dev mailing list