0

I have this existing Timer function:

            final Timer waveTimer = new Timer() {
                @Override
                public void run() { 
                    double value = r.getByte(); // takes quite long to finish
                    wave.renderWaveOnFly(value);
            }};
            waveTimer.scheduleRepeating(50);

However it works, the UI is "blocked" and that user can't click and do anything in the UI until the timer finishes when part of the UI calls waveTimer.cancel() which I created another Timer that cancels this timer after 10 seconds, so the UI is not usable until then.

Is there a way to implement a non-blocking timer such that it would pause for some time, perhaps just to make sure that the UI is not blocked and the user can still do something in the UI.

I mean, still have the feel that the UI is still responsive.

I am not sure about the figure, but say like every 100 millisec it stops and then give way for the UI and resume 100 millisec after the pause or something like this. I am thinking what approach to deal with.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
quarks
  • 33,478
  • 73
  • 290
  • 513
  • One should not do any costly operations in a UI thread! Use a separate thread for that. Or if ti can not be circumvented, display a "Loading..."/"Please wait..." screen, ideally along with a progress indicator . – ppeterka Oct 27 '12 at 11:32
  • @ppeterka I wish I could do that, but my application's function is to render a waveform out of the real-time bytes it gets from the flash object (of course wrapped with javascript) – quarks Oct 27 '12 at 11:38
  • 1
    Have a look at http://stackoverflow.com/questions/2590850/threading-in-gwt-client – Kennet Oct 27 '12 at 11:48
  • What is the package for the Timer you use ? – Krzysztof Zielinski Oct 30 '12 at 08:47

2 Answers2

1

The only way to do computations out of the UI thread in the browser is to use WebWorkers. There's no facility to use them in GWT though: worker code requires a specialized GWT linker, and creating a WebWorker is only possible through JSNI.

FYI, SpeedTracer uses WebWorkers.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
0

Can you change getBytes() method to be a asynchronous call ? Then the UI should not hang waiting for the method to finish.