在 jboss 客户端侧,当重复使用 UserTransaction 时存在内存泄漏。
例如:
private void testTransaction() throws Exception {
for(int i=1; i< 500000; i++) {
System.out.println("Starting process " + i);
// get the UserTransaction and EJB Proxy
Context ctx = getInitialContext(host, port, username, password);
UserTransaction tx = getUserTransaction(ctx);
ControllerRemote cr = (ControllerRemote)
ctx.lookup("Controller/Controller" + "!com.test.usertransaction.ControllerRemote");
try {
tx.begin();
}
catch(Exception ex1) {
ex1.printStackTrace();
}
//System.out.println("user transaction started");
cr.mainCall();
try {
tx.commit();;
}
catch(Exception ex1) {
ex1.printStackTrace();
throw ex1;
}
//System.out.println("commited user transaction");
if(ctx != null)
ctx.close();
}
}
该事务由远程客户端在部署于 EAP 7.3 上的 EJB 上执行。事务迭代了 50000 次。在迭代结束时观察到内存泄漏。32% 的内存被 org.wildfly.transaction.client.provider.remoting.TransactionClientChannel 占用。