• Post Reply Bookmark Topic Watch Topic
  • New Topic

Wait some time before execute next line in my code.  RSS feed

 
Frank Hamilton
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a problem with Spring mail lib. When I send a lot of message in a short time with org.springframework.mail.javamail.JavaMailSender.send() , is posible that the proccess return me a MailException with the SMTP code 421. I looking for 421 SMTP code in http://www.greenend.org.uk/rjk/2000/05/21/smtp-replies.html and I learned that this problem id refer to connection problem and that problem can resolve if you send mail again, without change in code.
Well, in my program there is some user and I need send mail to all. In this proccess is posible that 421 error code appear and some user don't get the message. For resolved the problem, my code need wait some second and try send again. How could I stop me program for 3 seg before send message again.

Any ideas¿¿¿ Thank so much.

 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would first try to solve the problem in the mail server; it's apparently flooded so it can't handle all the emails.

If you really need to wait, how about using the simple Thread.sleep approach?
 
Frank Hamilton
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank so much, Rob

Yes, maybe the smtp server is flooded, I'm speaking with administrator to solve it.

Finally I used this simple while statement to sleep the thread.



But definitely thread.sleep() is easier.
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, busy waiting. Haven't seen that in a while. It's a bad approach, as it will hog the CPU until the waiting is done. Just check your CPU usage during those 4 seconds, the JVM will use quite a bit of it.
 
Frank Hamilton
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
uuhh, thank so much, I never used this again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!