• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javamail: method blocks instead of throwing exception

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 56
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic