[jboss-user] [JNDI/Naming/Network] - very slow connection from client to server

blackwolff do-not-reply at jboss.com
Wed Feb 25 08:59:17 EST 2009


Hi,

why does the client always needs so much time (about 5-10 seconds) to get a connection to the jboss server? Even if I try to connect to the server the second or third time.

The client runs on a Windows-System, the JBoss-Server on a Linux-System.
If I do the same things with JBoss on Windows all works fine.


  | public class MyClass {
  | 
  |     public Object getSession() throws NamingException {
  | 	Object theObject = MyCache.getInstance().getSessionWithKey(getSessionName());
  | 	if(theObject == null) {
  | 	    theObject = getFromJNDI("MyEAR/" + getSessionName" + "/remote");
  | 	    MyCache.getInstance().setSessionWithKey(getSessionName(), theObject);
  | 	}
  | 		
  | 	return theObject;
  |     }
  |     
  |     private String getSessionName() {
  |         return "MySession";
  |     }
  | 
  |     private Object getFromJNDI(String name) throws NamingException {
  | 	Context ctx = null;
  | 	Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
  | 
  | 	try {
  | 	    ctx = getInitialContext();
  | 	    if (ctx == null)
  | 		return null;
  |     
  |     	    return ctx.lookup(name);
  | 	}  catch (NamingException ne) {
  | 	    throw ne;
  | 	}
  | 	finally {
  | 	    try {
  |                 ctx.close();
  | 	    } catch (NamingException ne1) {}
  | 	    
  | 	}
  |     }
  | 
  |     private Context getInitialContext() throws NamingException {
  | 	try {
  | 	    Properties properties = new Properties();
  | 	    properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
  | 	    properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  | 	    properties.put(Context.PROVIDER_URL, "jnp://anIpAdress:1099");
  | 	
  | 	    return new InitialContext(properties);
  | 	} catch (NamingException namingexception) {
  | 	    throw namingexception;
  | 	}
  |     }
  | 
  | }
  | 
  | 
  | 
  | public class MyCache
  | {
  |     private static MyCache inst = null;
  |     private HashMap sessionCache = new HashMap();
  | 
  |     private MyCache() {
  |         super();
  |     }
  | 
  |     public static MyCache getInstance() {
  |         if(inst == null) 
  |             inst = new MyCache();
  |         return inst;
  |     }
  | 
  |     public Object getSessionWithKey(String aName) {
  |         Object sessionObject = (Object)getSessionCache().get(aName);
  |         return sessionObject;
  |     }
  | 
  |     public void setSessionWithKey(String aName, Object anObject) {
  |         getSessionCache().put(aName, anObject);
  |     }
  | 
  |     public void clear() {
  |         setSessionCache(new HashMap());
  |     }
  |     
  | 
  |     public HashMap getSessionCache() {
  | 		return sessionCache;
  |     }
  | 
  | 
  |     public void setSessionCache(HashMap sessionCache) {
  | 	this.sessionCache = sessionCache;
  |     }
  | }
  | 
  | 
  | 
  | public interface MySession {
  |     public Collection doSomething();
  | }
  | 
  | 
  | @Stateless(mappedName = "MySession", name = "MySession")
  | @Remote(MySession.class)
  | @TransactionAttribute(TransactionAttributeType.REQUIRED)
  | public class MySessionBean implements MySession {
  | 	
  |     @PersistenceContext
  |     EntityManager em;
  | 
  |     public Collection doSomething() {
  | 	return new ArrayList();
  |     }
  | 
  | }
  | 

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4212986#4212986

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4212986



More information about the jboss-user mailing list