-
-
Notifications
You must be signed in to change notification settings - Fork 274
Description
I'm using simple-java-mail 6.4.3 with batch-module and try to understand how is it guaranteed for onSuccess
and onException
handlers that their setting will be performed before their usage?
AsyncOperationHelper
contains comment
Line 59 in 2ec2162
// by the time the code reaches here, the user would have configured the appropriate handlers |
But if I correctly understand it's still possible (if inner
NamedRunnable
will be executed fast) that Line 62 in 2ec2162
asyncResponseRef.get().delegateSuccessHandling(); |
E.g. I tried to perform simple test based on example from site:
AsyncResponse asyncResponse = mailer.sendMail(email, true);
asyncResponse.onSuccess(() -> System.out.println("Success"));
asyncResponse.onException((e) -> System.err.println("error"));
In this case the callback was executed successfully.
But if the main thread will sleep for some time, e.g.
AsyncResponse asyncResponse = mailer.sendMail(email, true);
Thread.sleep(10000);
asyncResponse.onSuccess(() -> System.out.println("Success"));
asyncResponse.onException((e) -> System.err.println("error"));
The callback was not executed at all because
Line 39 in 860a0d5
void delegateSuccessHandling() { |
onSuccess
method was not called yet and successHandler
was still null
.
Do I understand something wrong or is it a bug?
This can probably be solved if callbacks will be passed directly into the sendMail
method and then directly into the AsyncResponseImpl
constructor
Line 56 in 2ec2162
asyncResponseRef.set(new AsyncResponseImpl(executorService.submit(new NamedRunnable(processName) { |