When JavaMail is executed, all jframes are frozen
•
Java
I develop the program of automobile management system Then, when the car comes in and drives, I want to send an email to the boss of the company
In my program, it takes about 10 seconds to send an email
Solution
When you perform heavy tasks, you should run them in another thread, not like a GUI If you run in the event dispatch thread, the GUI will freeze until it is completed
You can use swing worker. Here is an example that I like very much
Example:
class Worker extends SwingWorker<String,Object> { @Override protected String doInBackground() throws Exception { //here you send the mail return "DONE"; } @Override protected void done() { super.done(); //this is executed in the EDT JOptionPane.showMessageDialog(null,"Message sent","Success",JOptionPane.INFORMATION_MESSAGE); } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码