Use following provided class as EJB service and deploy it on EAP 5.1.2.
Invoke startTest() method via EAP 5 JMX Console.
By calling asyncNullJob(), a "NullPointerException" is expected to be logged on server side, but there is nothing in the log.
Further investigation indicates that in FutureTask$Sync.innerRun() it does this with the exception:
�� try
{
result = callable.call();
�� }
catch (Throwable ex)
{
�� setException(ex);
return;
�� }
set(result);
Sets it in a sync object which would be why we can get it later with the Future. So to see the exception in the log when no FutureResult is called we would have to modify that org.jboss.ejb3.common.proxy.plugins.async.AsyncInterceptor$AsyncTask.call() method.
================================================
import java.util.concurrent.atomic.AtomicInteger;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import org.jboss.ejb3.annotation.LocalBinding;
import org.jboss.ejb3.annotation.Service;
import org.jboss.ejb3.common.proxy.plugins.async.AsyncUtils;
import org.jboss.logging.Logger;
@Service(objectName = "com.company.async:service=AsyncTestService")
@LocalBinding(jndiBinding = "com.company.async.AsyncProcessorLocal")
@TransactionManagement(TransactionManagementType.BEAN)
public class AsyncTestService implements AsyncTest, AsyncProcessorLocal {
/**
- Logger.
*/
private final Logger L = Logger.getLogger(this.getClass().getSimpleName());
/**
- The asynchronous version of this interface.
*/
private AsyncProcessorLocal asyncLocal = null;
/**
- Counter of the number of running contexts.
*/
public static AtomicInteger runningCounter = new AtomicInteger(0);
@Override
public String start() throws Exception
{
L.info("AsyncTestService.start() called");
asyncLocal = AsyncUtils.mixinAsync((AsyncProcessorLocal) this);
return "AsyncTestService.start() called";
}
@Override
public String stop() throws Exception
{
L.info("AsyncTestService.stop() called");
return "AsyncTestService.stop() called";
}
@Override
public String startTest() throws Exception
{
L.info("AsyncTestService.startTest() called");
int original = runningCounter.get();
asyncLocal.asyncJob();
Thread.currentThread().sleep(2000);
int afterJob = runningCounter.get(); // This should be 0 and it is 0
asyncLocal.asyncNullJob();
Thread.currentThread().sleep(2000);
int afterNullJob = runningCounter.get(); // This should be 0 but becomes
// 1.
runningCounter = new AtomicInteger(0);
// After four seconds this will be printed out
// "Concurrent Job: original >> 0, after job >> 0, after null job >> 1"
return "Concurrent Job: original >> " + original + ", after job >> "
+ afterJob + ", after null job >> " + afterNullJob;
}
@Override
public void asyncJob()
{
runningCounter.incrementAndGet();
Job job = new Job();
job.doJob();
runningCounter.decrementAndGet();
}
@Override
public void asyncNullJob()
{
runningCounter.incrementAndGet();
Job job = null;
job.doJob(); // I am expecting NullPiontException but thread just
// silently dropped.
// As a result, the counter is not decrement.
runningCounter.decrementAndGet();
}
}
class Job {
public void doJob()
{
return;
}
}
==============================================