6
6
import org .simplejavamail .email .Recipient ;
7
7
import org .simplejavamail .mailer .MailerGenericBuilder ;
8
8
import org .simplejavamail .mailer .config .TransportStrategy ;
9
+ import org .simplejavamail .mailer .internal .mailsender .concurrent .NamedRunnable ;
10
+ import org .simplejavamail .mailer .internal .mailsender .concurrent .NonJvmBlockingThreadPoolExecutor ;
9
11
import org .simplejavamail .mailer .internal .socks .AuthenticatingSocks5Bridge ;
10
12
import org .simplejavamail .mailer .internal .socks .SocksProxyConfig ;
11
13
import org .simplejavamail .mailer .internal .socks .socks5server .AnonymousSocks5Server ;
23
25
import java .util .List ;
24
26
import java .util .Properties ;
25
27
import java .util .concurrent .ExecutorService ;
26
- import java .util .concurrent .LinkedBlockingQueue ;
27
28
import java .util .concurrent .Phaser ;
28
- import java .util .concurrent .ThreadPoolExecutor ;
29
- import java .util .concurrent .TimeUnit ;
30
29
31
30
import static java .lang .String .format ;
32
31
import static org .simplejavamail .converter .EmailConverter .mimeMessageToEML ;
@@ -180,7 +179,7 @@ private static AnonymousSocks5Server configureSessionWithProxy(@Nonnull final Pr
180
179
* @param async If false, this method blocks until the mail has been processed completely by the SMTP server. If true, a new thread is started to
181
180
* send the email and this method returns immediately.
182
181
* @throws MailException Can be thrown if an email isn't validating correctly, or some other problem occurs during connection, sending etc.
183
- * @see Executors#newFixedThreadPool(int)
182
+ * @see NonJvmBlockingThreadPoolExecutor
184
183
*/
185
184
public final synchronized void send (final Email email , final boolean async ) {
186
185
/*
@@ -195,30 +194,14 @@ the proxy bridge server (or connection pool in async mode) while a non-async ema
195
194
if (async ) {
196
195
// start up thread pool if necessary
197
196
if (executor == null ) {
198
- ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor (
199
- operationalConfig .getThreadPoolSize (),
200
- operationalConfig .getThreadPoolSize (),
201
- operationalConfig .getThreadPoolTimeout (),
202
- TimeUnit .MILLISECONDS ,
203
- new LinkedBlockingQueue <Runnable >(),
204
- new NamedThreadFactory ("Simple Java Mail async mail sender" )
205
- );
206
- if (operationalConfig .getThreadPoolTimeout () > 0 ) {
207
- threadPoolExecutor .allowCoreThreadTimeOut (true );
208
- }
209
- executor = threadPoolExecutor ;
197
+ executor = new NonJvmBlockingThreadPoolExecutor (operationalConfig , "Simple Java Mail async mail sender" );
210
198
}
211
199
configureSessionWithTimeout (session , operationalConfig .getSessionTimeout ());
212
- executor .execute (new Runnable ( ) {
200
+ executor .execute (new NamedRunnable ( "sendMail process" ) {
213
201
@ Override
214
202
public void run () {
215
203
sendMailClosure (session , email );
216
204
}
217
-
218
- @ Override
219
- public String toString () {
220
- return "sendMail process" ;
221
- }
222
205
});
223
206
} else {
224
207
sendMailClosure (session , email );
0 commit comments