Hi all,
Pretty sure all of these approaches will work, but I'd appreciate opinions on which is the best.
Consider for argument's sake the (unfortunate) scenario where you have UI changing code and reasonably intensive (average 500ms) logic code mixed and inseparable. all of the changing ui components are on the one panel.
01 new Thread(){
02 public void run(){
03
04 for (int i = 0; i < 100; i++){
05 // some processing
06 doSomething();
07 // update some ui components
08 panel.doSomeUi();
09 }
10
11 panel.revalidate();
12 panel.repaint();
13
14 }}.start();
Which of the following 3 approaches would you choose and why?
- wrap all code in invokeLater
- call invokeLater inside doSomeUi() and then again for revalidate/repaint
- only use invokeLater for revalidate/repaint at end
For mine:
option 1 would hang the Event Processing Thread (EPT) while all of the processing occurs
option 2 would have overhead considerations with many new runnables being created and in special cases may cause the ui to update in a half complete state if components need some of the subsequent ui changes to be valid
option 3 would be the most efficient but may have some thread safety issues
keen to hear other opinions.