0
從下面的代碼我試圖訪問遠程計算機上的EJB。如何在glassfish上設置JNDI查找超時
該代碼在Glassfish 4.1上運行。在Web應用程序中。
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("org.omg.CORBA.ORBInitialHost","X.X.X.X");
props.setProperty("org.omg.CORBA.ORBInitialPort","3700");
//timeouts
props.setProperty("sun.rmi.transport.connectionTimeout","5000");
props.setProperty("sun.rmi.transport.tcp.handshakeTimeout","5000");
props.setProperty("sun.rmi.transport.tcp.responseTimeout","5000");
props.setProperty("sun.rmi.transport.tcp.readTimeout","5000");
props.setProperty("com.sun.corba.ee.transport.ORBWaitForResponseTimeout","5000");
props.setProperty("com.sun.corba.ee.transport.ORBTCPConnectTimeouts", "100:500:100:500");
props.setProperty("com.sun.corba.ee.transport.ORBTCPTimeouts", "500:2000:50:1000");
System.setProperty("com.sun.corba.ee.transport.ORBWaitForResponseTimeout","5000");
System.setProperty("com.sun.corba.ee.transport.ORBTCPConnectTimeouts","100:500:100:500");
System.setProperty("com.sun.corba.ee.transport.ORBTCPTimeouts","500:2000:50:1000");
System.setProperty("sun.rmi.transport.connectionTimeout","5000");
System.setProperty("sun.rmi.transport.tcp.handshakeTimeout","5000");
System.setProperty("sun.rmi.transport.tcp.responseTimeout","5000");
System.setProperty("sun.rmi.transport.tcp.readTimeout","5000");
//timeout
InitialContext ctx = new InitialContext(props);
MyRemoteInterface bean = (MyRemoteInterface)
ctx.lookup("ejbname#EjbName");
如果查找成功 - 一切正常。
但是,問題是,如果遠程機器不可用,則代碼將掛起ctx.lookup("ejbname#EjbName");
。的時間不同,原因,超過1 min 20 seconds
如果IP是不存在的,並在10 minutes
如果遠程計算機是在防火牆後面,直到它引發查找失敗例外:
Severe: org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure:
...
...
Caused by: java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Net.java:101)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:622)
at com.sun.corba.ee.impl.misc.ORBUtility.openSocketChannel(ORBUtility.java:110)
at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:329)
這裏有另外一個原因:
Caused by: java.net.ConnectException: Connection timed out: connect
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:454)
at sun.nio.ch.Net.connect(Net.java:446)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648)
at com.sun.corba.ee.impl.misc.ORBUtility.openSocketChannel(ORBUtility.java:110)
at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:329)
我不想等那麼久才發現查找失敗。我上面設置的所有超時都沒有幫助。如何設置查找超時或是否有其他解決方法?
謝謝。
您的意思是** JNDI **查找超時?如果是這樣,你的標題和標籤不正確。 – EJP
@EJP是的JNDI - 謝謝 - 修正它。 – Plirkee