This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javamail: method blocks instead of throwing exception

 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have the following code in a Swing/Spring application:


When the email address I try and send the message to is erroneous i.e. julien@domain or julien@domainDoesNotExist.com the above method blocks indefinitely without throwing any exception...

Note that it runs within a SwingWorker.

Can anyone please help?

Thanks in advance,

Julien.
 
Ramon Anger
Ranch Hand
Posts: 56
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Julien,

why not throw your own TimeoutException after x seconds?

Cheers,
Ramon
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ramon,
I altered my app as follows:


Now I do rethrow a RuntimeException. However it still blocks and no rollback is performed...
Any other idea?
J.
 
Ramon Anger
Ranch Hand
Posts: 56
Chrome Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Julien,

I'm afraid this is not exactly what I meant. Please try the following:

1. Sending your mails has to happen in its own Thread.
2. In case your mail sending thread has successfully send the mail, you set a variable back in your main thread.
3. In your main thread you set a timer or something that realizes how many time has been spent.
4. After your time limit has been reached, you could check whether the mail sending thread set that variable yet (see 2.). If not, stop that thread and you could go on in your main thread.

BTW: Are you sure, that the mail connection you use to send that email, has no timeout parameter that can be set?

Cheers,
Ramon
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point Ramon.
First: I dropped the thread implementation: it now execute sequentially.
Second: upon your advice, I added this to my javamailsender bean:

I have the same behavior as before.
Julien.
 
Ramon Anger
Ranch Hand
Posts: 56
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Julien,

a value of 1000 would mean timeout after 1 second.
Can you ensure that the properties you've set are known to your mail session at runtime?
There should be a Session.getProperties() method and/or Session.getProperty("mail.smtp.connectiontimeout") method.

If not set, mail.smtp.connectiontimeout and mail.smtp.timeout are both infinite and that's the behaviour your code shows ...

Cheers,
Ramon
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked that my JavaMailSenderImpl does have a getJavaMailProperties method and also that the values are in the mailSender's session.

and

However, it does seem those properties are ignored...
Regards,
Julien.
 
Paul Clapham
Sheriff
Posts: 20713
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're trying to debug JavaMail, one of the recommended things to try is turning on debug mode, so you can see the conversation between your code and the server.

However you seem to be trying to debug JavaMail and Spring at the same time. I recommend putting Spring aside and debugging JavaMail by itself to start with, otherwise you don't know whether you are debugging JavaMail or Spring.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic