我在调用异步方法时有一种奇怪的行为,该方法是在一个循环内调用两次迭代。实际上它被调用了两次,但是上次参数值被调用。但是这些参数在循环中被改变了。
Example :
first iteration : tenant_id=11
second iteration :tenant_d=10
在调试异步函数时,两次调用参数值为10 !!
异步功能:
@Stateless
public class StatisticsMigrator {
@Asynchronous
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void doMigrate(final ConnectionParameters params) {
LOG.debug("migration has been started in asynchronous mode);
}
}
@Path("{/endpoint}")
public class WebService
{
@Inject
StatisticsMigrator migrator;
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/general/")
public Response migrate(@Context final HttpHeaders
argHeaders)
{
ConnectionParameters par=ConnectionParameters.creatConnectionParamsObject(baseUri, argHeaders.getHeaderString("Authorization"),tenantId);
for (Tenant tenant : tenants) {
par.setTenantId(String.valueOf(tenant.getRetailerId()));
migrator.doMigrate(par);
}
}
}