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.

4
  • 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 . Commented Oct 27, 2012 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) Commented Oct 27, 2012 at 11:38
  • 1
    Have a look at stackoverflow.com/questions/2590850/threading-in-gwt-client Commented Oct 27, 2012 at 11:48
  • What is the package for the Timer you use ? Commented Oct 30, 2012 at 8:47

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.