Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: java mail and thread Date: Sat, 26 Oct 2013 13:07:44 +0200 Lines: 27 Message-ID: References: <6615a997-f18f-42b0-812e-de1cbadf8341@googlegroups.com> <1tainohfwpuj1.1v1jokfkdmezh.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net EBkL6SHtCG5bisRIoA9cEw2rD6cr0Me/TylTBNg2x+xCWSjJU= Cancel-Lock: sha1:ph923XAuRpKGO2RCj6hQlR2pgzs= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 In-Reply-To: <1tainohfwpuj1.1v1jokfkdmezh.dlg@40tude.net> X-Antivirus: avast! (VPS 131026-1, 26.10.2013), Outbound message X-Antivirus-Status: Clean Xref: csiph.com comp.lang.java.programmer:26433 On 25.10.2013 13:45, Joerg Meier wrote: > On Thu, 24 Oct 2013 14:28:49 -0700 (PDT), andros976@gmail.com wrote: > >> I noticed that this statement takes a bit of seconds before releasing >> flow and therefore are unable to use the other functions of the application . I thought , therefore, to use a technology where each object of the class that sends the email implements Runnable and then i use it like a thread. >> I noticed , however, that there are problems because sometimes 20 over 50 emails fail and the instruction that give me the error is > >> Transport.send (msg ) ; > >> java.net.SocketException : Connection closed by remote host > > Possibly the remote server doesn't allow multiple (or more than 2 or 3) > connections at the same time. I recommend writing a thread class that keeps > an internal list of mails to send, and sends them one by one. That way, > when you send two mails at the same time, the 2nd gets added to the list > and sent after the first finishes, instead of at the same time. Or create a thread pool with as many threads as concurrent connections are allowed. Then feed send requests through a queue. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/