java.net.BindException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Re: Need help in setting up RMI Server as Standalone
    via by gerald ternola,
  • Hello, we use Ehcache as 2nd level Hibernate cache only, having RMI replication enabled with all the following ports statically set: - net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory multicastGroupPort - net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory port remoteObjectPort However the last one (remoteObjectPort) causes troubles when application is restarted without restarting the whole application server. I noticed that when ehcache starts it creates sockets for all those configured ports and when it's stopped but the application server left running all these sockets remain open. When it's started again then, with the first two mentioned ports there appears to be no problem, but for remoteObjectPort we get the followin exception: Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not instantiate cache implementation at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:737) at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:224) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:291) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) ... 143 more Caused by: org.hibernate.HibernateException: Could not instantiate cache implementation at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:64) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:214) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730) ... 148 more Caused by: org.hibernate.cache.CacheException: net.sf.ehcache.CacheException: Problem starting listener for RMICachePeer null. Initial cause was Port already in use: 41103; nested exception is: java.net.BindException: Address already in use at net.sf.ehcache.hibernate.EhCacheProvider.buildCache(EhCacheProvider.java:96) at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:61) ... 152 more Caused by: net.sf.ehcache.CacheException: Problem starting listener for RMICachePeer null. Initial cause was Port already in use: 41103; nested exception is: java.net.BindException: Address already in use at net.sf.ehcache.distribution.RMICacheManagerPeerListener.notifyCacheAdded(RMICacheManagerPeerListener.java:529) at net.sf.ehcache.event.CacheManagerEventListenerRegistry.notifyCacheAdded(CacheManagerEventListenerRegistry.java:157) at net.sf.ehcache.CacheManager.addCacheNoCheck(CacheManager.java:708) at net.sf.ehcache.CacheManager.addCache(CacheManager.java:685) at net.sf.ehcache.CacheManager.addCache(CacheManager.java:643) at net.sf.ehcache.hibernate.EhCacheProvider.buildCache(EhCacheProvider.java:90) ... 153 more Caused by: java.rmi.server.ExportException: Port already in use: 41103; nested exception is: java.net.BindException: Address already in use at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:284) at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:219) at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:398) at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:131) at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:195) at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:306) at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:269) at java.rmi.server.UnicastRemoteObject.<init>(UnicastRemoteObject.java:168) at net.sf.ehcache.distribution.RMICachePeer.<init>(RMICachePeer.java:65) at net.sf.ehcache.distribution.RMICacheManagerPeerListener.notifyCacheAdded(RMICacheManagerPeerListener.java:525) ... 158 more Caused by: java.net.BindException: Address already in use at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:417) at java.net.ServerSocket.bind(ServerSocket.java:342) at java.net.ServerSocket.<init>(ServerSocket.java:208) at java.net.ServerSocket.<init>(ServerSocket.java:120) at sun.rmi.transport.proxy.RMIDirectSocketFactory.createServerSocket(RMIDirectSocketFactory.java:46) at sun.rmi.transport.proxy.RMIMasterSocketFactory.createServerSocket(RMIMasterSocketFactory.java:350) at sun.rmi.transport.tcp.TCPEndpoint.newServerSocket(TCPEndpoint.java:638) at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:272) ... 167 more So it tried to create the same socket again and thus fails. Simple workaround is to not specify the static value for remoteObjectPort so that it another socket is open, however this could lead to many sockets left open after series ot application restarts and also disallows the use of static port in there.
    via by Petr H,
    • java.net.BindException: Address already in use at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:310) at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:218) at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:393) at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:129) at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:190) at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:293) at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:235) at java.rmi.server.UnicastRemoteObject.<init>(UnicastRemoteObject.java:133) at org.apache.jcs.auxiliary.remote.server.RemoteCacheServer.<init>(RemoteCacheServer.java:111)
    No Bugmate found.