当我运行ejb3远程客户端服务部署在服务器WildFly8.1.0 Final
中时,我得到了预期的结果。但是现在我正在尝试对此进行基准测试,当我通过JMH @Benchmark
方法运行客户端时,它可以正常运行,但是在预热过程中进行了一些迭代后,会出现以下错误。
Mar 04, 2015 12:29:15 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@13689c
56, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@25d8cd6c,channel=jboss.ejb,nodename=mast
er:server-three]} on channel Channel ID c1426f51 (outbound) of Remoting connection 3836a177 to /192.168.17.150:8330
Result is given by [ host: isurug ], [ Result: ONE ]
____ejb:poc_ear-1.0/poc_ejbs-1.0//DataGridServiceImpl!com.oms.ejbs.stateless.DataGridService
Mar 04, 2015 12:29:15 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
Mar 04, 2015 12:29:15 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@538da6
b, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@25d8cd6c,channel=jboss.ejb,nodename=maste
r:server-three]} on channel Channel ID bed866b3 (outbound) of Remoting connection 3836a177 to /192.168.17.150:8330
Result is given by [ host: isurug ], [ Result: ONE ]
____ejb:poc_ear-1.0/poc_ejbs-1.0//DataGridServiceImpl!com.oms.ejbs.stateless.DataGridService
Mar 04, 2015 12:29:15 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver$1 handleFailed
ERROR: Failed to open channel for context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@62af85f9, receiver=Remoting connection EJB rece
iver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@25d8cd6c,channel=jboss.ejb,nodename=master:server-three]}
org.jboss.remoting3.ProtocolException: Too many channels open
at org.jboss.remoting3.remote.RemoteConnectionHandler.handleOutboundChannelOpen(RemoteConnectionHandler.java:185)
at org.jboss.remoting3.remote.RemoteConnectionHandler.open(RemoteConnectionHandler.java:318)
at org.jboss.remoting3.ConnectionImpl.openChannel(ConnectionImpl.java:75)
at org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection.openChannel(ConnectionPool.java:227)
at org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver.associate(RemotingConnectionEJBReceiver.java:169)
at org.jboss.ejb.client.EJBClientContext.registerEJBReceiver(EJBClientContext.java:375)
at org.jboss.ejb.client.EJBClientContext.registerEJBReceiver(EJBClientContext.java:327)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:159)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:115)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:47)
at org.jboss.ejb.client.EJBClientContext.getCurrent(EJBClientContext.java:271)
at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:281)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:176)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
at com.sun.proxy.$Proxy1.getData(Unknown Source)
at com.oms.client.EJBInvoker.invokeDataGridService(EJBInvoker.java:71)
at com.test.MyBenchmark.testEjbClient(MyBenchmark.java:43)
at com.test.generated.MyBenchmark_testEjbClient.testEjbClient_avgt_jmhLoop(MyBenchmark_testEjbClient.java:160)
at com.test.generated.MyBenchmark_testEjbClient.testEjbClient_AverageTime(MyBenchmark_testEjbClient.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.openjdk.jmh.runner.LoopBenchmarkHandler$BenchmarkTask.call(LoopBenchmarkHandler.java:210)
at org.openjdk.jmh.runner.LoopBenchmarkHandler$BenchmarkTask.call(LoopBenchmarkHandler.java:192)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
错误提示
too many channels open
,这样通话后我应该关闭通道吗?或者是什么原因造成的,如何解决?以下是我的远程客户端。
public class EJBInvoker {
/**
* Invoke Data Grid Service.
*/
public void invokeDataGridService() {
EJBInvoker client = null;
try {
for (int i = 0; i < 1; i++) {
client = new EJBInvoker();
String dataGridServiceJndi = "ejb:poc_ear-1.0/poc_ejbs-1.0//DataGridServiceImpl!com.oms.ejbs.stateless.DataGridService";
DataGridService dataGridService = (DataGridService) client.lookupRemoteEJB(dataGridServiceJndi);
String result = dataGridService.getData("1");
System.out.println(result);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Lookup for Remote EJB
*
* @return {@link Object} instance.
* @throws NamingException
* naming exception.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private Object lookupRemoteEJB(String jndiName) throws NamingException {
Context context = null;
try {
Properties clientProperties = new Properties();
clientProperties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
clientProperties.put("remote.connections", "default");
clientProperties.put("remote.connection.default.port", "8330");
clientProperties.put("remote.connection.default.host", "192.168.17.150");//192.168.16.40
clientProperties.put("remote.connection.default.username", "admin");
clientProperties.put("remote.connection.default.password", "1qaz2wsx@");
clientProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(clientProperties);
ContextSelector<EJBClientContext> contextSelector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);
EJBClientContext.setSelector(contextSelector);
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
context = new InitialContext(properties);
System.out.println("____" + jndiName);
return context.lookup(jndiName);
} finally {
if (context != null) {
context.close();
}
}
}
}
最佳答案
我们不能创建太多的InitialContext。在我的应用程序中,我将InitialContext设置为静态变量。因此在整个应用中,只有一个实例。
那解决了问题。