I am trying to save the result of the login process for statistics in a database asynchronously in order to save time during the login method. But for some reason, the login process takes longer if I add thread.sleep to the async method. Why is this? I thought the authentication method would not wait for the writeResultToStats method to complete.
@Stateless @LocalBean @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER) @TransactionManagement(TransactionManagementType.CONTAINER) public class CustomerBeanTest { @PersistenceContext(unitName = WebPersistenceUnits.QISADS) private EntityManager em_local; @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void authenticate(Long loginid, String cmppassword) { try { Login l = em_local.find(Login.class, loginid); String s = l.getPassword(); if (!s.equalsIgnoreCase(cmppassword)) throw new PasswordMissmatchException(); writeResultToStats(loginid, true); } catch (PasswordMissmatchException e) { writeResultToStats(loginid, false); } } @Asynchronous @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) private void writeResultToStats(Long loginID, boolean success) { try {
source share