What must qualify as a "long running task" to run on a SwingWorker thread?

I know how to use SwingWorker threads, but I still don't have the exact criteria to decide when to use them or not.

I / O seems obvious, but what about methods that deal with potentially large collections?

The criterion may be the actual running time, but how much (in ms) will qualify?

+2


source to share


5 answers


What matters is how responsive the user interface is.

Jef Raskin (of Mac UI glory) said the maximum latency should be limited to 50ms. RISC OS recommendations say 100ms. The button press is around 50ms, so if you want to act on release, you need to act quickly as the custom model is usually pressed for an action. Above 140ms not only reacts to some reactions, but UI responses are disconnected from user actions (see, for example, O'Reilly Mind Hacks).

250-350ms and the (normal) user will think something went wrong.



On the other hand, you need 8 fps (and includes rendering) to have the illusion of an animation of (for example) scrolling. And you know how players love their fps.

However, I prefer software that works more or less than the best possible software that is not available. Having said that, if Opera closes for a few minutes while it clogs a disc in the middle of this edit, I didn't like it.

+3


source


For me it will be 1 s.

If your processing takes longer, your UI will freeze. In this situation, it is much better to show a "busy" paint or progress bar.



How long would you like to expect ANY app you use to become responsive? Let's say you open your IDE or MS-Word or whatever. If you notice most of the time when the application is loading, a progress bar or some other animation is displayed, even if the document / project / everything is small enough to open after 2s.

+1


source


There is no specific number, it is a matter of what the application should do and how flexible the gui should be. The best approach is to do some tests, no one can answer that for you. (although comments can be very helpful to you in determining what testing you need to do)

0


source


The long term task will be long enough for the user to notice glitches or delays while redrawing the user interface. Setting the label text is probably not "long," and simply removing a few milliseconds to draw the image to the splash screen can delay the UI redrawing long enough to be noticeable.

0


source


Basically, if you cannot predict how long the processing will take, it would be a good idea to put it on a separate thread, as it will keep your application responsive even in extreme cases with bad data, etc. Good candidates

  • Performing expensive operations on all fields in the model.
  • Depending on the external data source or destination. You never know if it might be a slow network drive or something similar.

But why not just just create a rule, if it has a loop (any for / while) then it goes to SwingWorker?

0


source







All Articles