HGA03630@nifty.ne.jp (hiwa) wrote in message news:<6869384d.0310041636.72b8f108@posting.google. com>...[color=blue]
>
viator@rediffmail.com (viator) wrote in message news:<dc828419.0310030952.31dd4fb4@posting.google. com>...
> Read the javadoc for javax.swing.SwingUtilities#invokeLater() method
> and linked documentations from there. Your time-consuming task should
> run as a separate thread separated from Swing GUI rendering
> thread(a.k.a. AWT event dispatch thread).[/color]
I tried the following two methods. . .
One using the SwingWorker Class. . .
public void actionPerformed(ActionEvent evt){
Object o=evt.getSource();
if(o==cmdRun||o==txtInput){
final SwingWorker worker=new SwingWorker(){
public Object construct(){
/* the time consuming part */
runMachine();
return null;
}
};
worker.start();
}
/* other handlers . . .*/
}
And other one by implementing Runnable like this…
public void actionPerformed(ActionEvent evt){
Object o=evt.getSource();
if(o==cmdRun||o==txtInput){
/* the time consuming part */
/* here the time consuming part it in the run method of this class*/
new Thread(this).start();
}
/* other handlers . . .*/
}
Is the second implementation violates single thread rule? Please note
that the user interface is also updated by "Time consuming part" to
render outputs. Although both the method are working fine. which one
is better though?