5 Replies Latest reply on Aug 11, 2004 1:42 PM by Chuck Harris

    javax.naming.CommunicationException - help

    Chuck Harris Newbie

      I have been going though the sun ejb tutorial and have run into an intermitant problem.
      The Converter example (stateless) deploys fine and runs without error unless I hit it with
      multiple client requests. I threaded the client to simulate multiple concurrent client
      requests. If I run the client, it will generate some variation of the following logging on the
      client but only occasionally. I can run the client from different command prompts at the same
      time and both will run without error. Occasionally, it fails and there is no pattern to it.
      The error will generate if run from the same machine or remotely.
      If i run the client to make 1000 requests (see main below), it does not fail even if running in
      two windows. The os is win2k, jboss 3.2.5 and Java is 1.4.2._04. Is there a setting in
      ejb-jar.xml or jboss.xml that I need to include or change? Or other? Thanks. I posted a me
      too on http://www.jboss.org/index.html?module=bb&op=viewtopic&t=52342. It looks like we are
      both experiencing a similar issue.

      snipit from the client:

      public static void main(String[] args)
       {
       boolean b = false;
       if (b)
       {
       for (int i=0;i<1000;i++)
       {
       ConverterClient cc = new ConverterClient();
       cc.run();
       }
       }
       else
       {
       for (int i=0;i<14;i++)
       {
       ConverterClient cc = new ConverterClient();
       cc.execute();
       }
       }
       }
      
       public void execute()
       {
      
       Thread t = new Thread(this);
       t.start();
      
       }
       public void run()
       {
       try
       {
       Hashtable properties = new Hashtable();
       properties.put(Context.INITIAL_CONTEXT_FACTORY,
       "org.jnp.interfaces.NamingContextFactory");
      
       properties.put(Context.PROVIDER_URL,"jnp://myip:1099");
       properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interface");
       //properties.put(Context.BATCHSIZE,"1000");
       //properties.put("jnp.socketFactory","org.jnp.interfaces.TimedSocketFactory");
       //properties.put("jnp.timeout","0");
      
       Context initial = new InitialContext(properties);
      
      
       Object objref = initial.lookup("aRemote");
      
       ConverterHome home =
       (ConverterHome)PortableRemoteObject.narrow(objref,
       ConverterHome.class);
      
       Converter currencyConverter = home.create();
      
       BigDecimal param = new BigDecimal ("100.00");
       BigDecimal amount = currencyConverter.dollarToYen(param);
       System.out.println(amount);
       amount = currencyConverter.yenToEuro(param);
       System.out.println(amount);
       currencyConverter.remove();
       home.remove(currencyConverter.getHandle());
       initial.close();
       }
       catch (Exception ex)
       {
       System.err.println("Caught an unexpected exception!");
       ex.printStackTrace();
       }
       }


      Logging:

      log4j:WARN No appenders could be found for logger (org.jnp.interfaces.NamingContext).
      log4j:WARN Please initialize the log4j system properly.
      12160.00
      0.77
      12160.00
      0.77
      12160.00
      12160.00
      12160.00
      0.77
      0.77
      12160.00
      12160.00
      12160.00
      0.77
      0.77
      0.77
      12160.00
      12160.00
      12160.00
      0.77
      0.77
      12160.00
      0.77
      0.77
      0.77
      Caught an unexpected exception!
      javax.naming.CommunicationException: Receive timed out [Root exception is

      java.net.SocketTimeoutException: Receive
      timed out]
      at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1119)
      at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1196)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:516)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at ejb.stateless.ConverterClient.run(Unknown Source)
      at java.lang.Thread.run(Thread.java:534)
      Caused by: java.net.SocketTimeoutException: Receive timed out
      at java.net.PlainDatagramSocketImpl.peekData(Native Method)
      at java.net.DatagramSocket.receive(DatagramSocket.java:661)
      at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1089)
      ... 6 more
      Caught an unexpected exception!
      javax.naming.CommunicationException: Receive timed out [Root exception is

      java.net.SocketTimeoutException: Receive
      timed out]
      at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1119)
      at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1196)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:516)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at ejb.stateless.ConverterClient.run(Unknown Source)
      at java.lang.Thread.run(Thread.java:534)
      Caused by: java.net.SocketTimeoutException: Receive timed out
      at java.net.PlainDatagramSocketImpl.peekData(Native Method)
      at java.net.DatagramSocket.receive(DatagramSocket.java:661)
      at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1089)
      ... 6 more

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'
      
      'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
      <ejb-jar>
       <display-name>aRemote</display-name>
       <enterprise-beans>
       <session>
       <description>A test ejb</description>
       <display-name>aRemote</display-name>
       <ejb-name>aRemote</ejb-name>
       <home>stateless.ConverterHome</home>
       <remote>ejb.stateless.Converter</remote>
       <ejb-class>ejb.stateless.ConverterBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
       <security-identity>
       <description/>
       <use-caller-identity/>
       </security-identity>
       </session>
       </enterprise-beans>
       <assembly-descriptor>
       <container-transaction>
       <method>
       <ejb-name>aRemote</ejb-name>
       <method-name>*</method-name>
       </method>
       <trans-attribute>Supports</trans-attribute>
       </container-transaction>
       </assembly-descriptor>
      </ejb-jar>


      <?xml version="1.0"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN"
       "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
      <!-- Version: $Id: jboss.xml,v 1.6.2.4 2003/07/29 00:06:20 sreich Exp $ -->
      <jboss>
       <enterprise-beans>
       <session>
       <ejb-name>aRemote</ejb-name>
       </session>
       </enterprise-beans>
      </jboss>




        • 1. Re: javax.naming.CommunicationException - help
          Chuck Harris Newbie

          Running the client looping to 1000 from a remote is causing the following error. Sorry for the mis statement. Not sure if this is related or a different issue. The client is getting a return from the ejb and exception is being thrown also:
          12160.00
          0.77
          Caught an unexpected exception!
          java.rmi.ServerException: Could not get EJBObject; nested exception is:
          javax.naming.NoInitialContextException: Need to specify class name in environment or
          system property, or as an a
          pplet parameter, or in an application resource file: java.naming.factory.initial
          at
          org.jboss.proxy.ejb.handle.StatelessHandleImpl.getEJBObject(StatelessHandleImpl.java:83)
          at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:139)
          at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
          at $Proxy0.remove(Unknown Source)
          at ejb.stateless.ConverterClient.run(Unknown Source)
          at ejb.stateless.ConverterClient.main(Unknown Source)
          Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or
          system property, or as a
          n applet parameter, or in an application resource file: java.naming.factory.initial
          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
          at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
          at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
          at javax.naming.InitialContext.lookup(InitialContext.java:347)
          at
          org.jboss.proxy.ejb.handle.StatelessHandleImpl.getEJBObject(StatelessHandleImpl.java:76)
          ... 5 more
          12160.00
          0.77
          Caught an unexpected exception!
          java.rmi.ServerException: Could not get EJBObject; nested exception is:
          javax.naming.NoInitialContextException: Need to specify class name in environment or
          system property, or as an a
          pplet parameter, or in an application resource file: java.naming.factory.initial
          at
          org.jboss.proxy.ejb.handle.StatelessHandleImpl.getEJBObject(StatelessHandleImpl.java:83)
          at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:139)
          at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
          at $Proxy0.remove(Unknown Source)
          at ejb.stateless.ConverterClient.run(Unknown Source)
          at ejb.stateless.ConverterClient.main(Unknown Source)
          Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or
          system property, or as a
          n applet parameter, or in an application resource file: java.naming.factory.initial
          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
          at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
          at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
          at javax.naming.InitialContext.lookup(InitialContext.java:347)
          at
          org.jboss.proxy.ejb.handle.StatelessHandleImpl.getEJBObject(StatelessHandleImpl.java:76)
          ... 5 more

          • 2. Re: javax.naming.CommunicationException - help
            Chuck Harris Newbie

            I removed:
            home.remove(currencyConverter.getHandle());
            initial.close();
            and the errors from the remote client in the second post are not thrown. The intermittant error in the first post are still an issue.

            • 3. Re: javax.naming.CommunicationException - help
              Chuck Harris Newbie

              I have tested the Converter ejb in two other testing envronments. Both still generate errors (see below) but with many more threads. It seems that this is a system/network issue. The first environment is win2003/dual zeon processor servers and errors started occuring with two clients running 300 threads each. See previous post for client. The second is win2k server and errors started showing at 200 threads each. Can the timeout period be set?

              javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed
              out]
              at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1115)
              at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1192)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:514)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:507)
              at javax.naming.InitialContext.lookup(InitialContext.java:347)
              at ejb.stateless.ConverterClient.run(Unknown Source)
              at java.lang.Thread.run(Thread.java:534)
              Caused by: java.net.SocketTimeoutException: Receive timed out
              at java.net.PlainDatagramSocketImpl.peekData(Native Method)
              at java.net.DatagramSocket.receive(DatagramSocket.java:661)
              at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1093)
              ... 6 more

              • 4. Re: javax.naming.CommunicationException - help
                Scott Stark Master

                The default win32 socket configurations are notorious for not being able to deal with a large number of sockets. See the http://www.winguides.com/registry/category.php?310 for the tcp/ip registry parameters. More reasonable defaults for testing are:

                Windows Registry Editor Version 5.00
                
                [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]
                "MaxUserPort"=dword:0000fffe
                "TcpTimedWaitDelay"=dword:0000001e
                "MaxFreeTcbs"=dword:00003e80
                "MaxHashTableSize"=dword:00004000
                "TcpNumConnections"=dword:00fffffe
                "MaxFreeTwTcbs"=dword:00061a80
                "TcpWindowSize"=dword:00060000
                "NumTcbTablePartitions"=dword:00000020
                



                • 5. Re: javax.naming.CommunicationException - help
                  Chuck Harris Newbie

                  I made the reg changes on the win2k boxes and did get a performance increase. The number of threads it took to cause the javax.naming.CommunicationException was increased. I added failover to the client to catch and retry. How does this look? Will it cause other problems?

                   public void run()
                   {
                   try
                   {
                   Hashtable properties = new Hashtable();
                   properties.put(Context.INITIAL_CONTEXT_FACTORY,
                   "org.jnp.interfaces.NamingContextFactory");
                   properties.put(Context.PROVIDER_URL,m_providerUrl);
                   properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interface");
                   Context initial = new InitialContext(properties);
                   Object objref = initial.lookup("aRemoteEntirex");
                   ConverterHome home =
                   (ConverterHome)PortableRemoteObject.narrow(objref,
                   ConverterHome.class);
                   Converter currencyConverter = home.create();
                   BigDecimal param = new BigDecimal ("100.00");
                   BigDecimal amount = currencyConverter.dollarToYen(param);
                   System.out.println(amount + " 1 " + Thread.currentThread().getName());
                   amount = currencyConverter.yenToEuro(param);
                   System.out.println(amount + " 2 " + Thread.currentThread().getName());
                   currencyConverter.remove();
                   }
                   catch(javax.naming.CommunicationException e)
                   {
                   if (e.getCause().toString().indexOf("java.net.SocketTimeoutException") != -1)
                   {
                   //System.out.println("Socket timout " + e.getCause().toString()
                   // + Thread.currentThread().getName());
                   ++m_errorCount;
                   if (m_errorCount < 50)
                   {
                   System.out.println("Socket timout retrying " + Thread.currentThread().getName());
                   this.run();
                   }
                   else
                   {
                   System.out.println("Socket timout retry failed " + Thread.currentThread().getName());
                   //Do something;
                   }
                   }
                   else
                   {
                   System.out.println("Socket DIDNOT timout " + e.getCause().toString());
                   }
                   }
                   catch (Exception ex)
                   {
                   System.err.println("Caught an unexpected exception!" + Thread.currentThread().getName());
                   ex.printStackTrace();
                   }
                   }
                  }