在Java RMI(Remote Method Invocation)应用程序开发中,java.rmi.AlreadyBoundException是一个比较常见的异常。 一、分析问题背景 java.rmi.AlreadyBoundException异常的产生,通常是在RMI服务器端进行对象注册时出现的。 registry.bind("RemoteService", obj); // 这里将抛出AlreadyBoundException 二、可能出错的原因 导致java.rmi.AlreadyBoundException 四、正确代码示例 为了避免java.rmi.AlreadyBoundException,在绑定之前应先检查名称是否已经存在,或使用rebind()方法替代bind()方法。 使用rebind()方法来覆盖已经存在的绑定,从而确保不会抛出AlreadyBoundException。
前言:异步网络编程中的“一次性”铁律在JavaNIO和AIO的网络编程模型中,AlreadyBoundException是一个看似简单却至关重要的状态哨兵。 1.2NIO/AIO绑定异常家族AlreadyBoundException是网络通道状态异常体系的一部分:异常类触发条件父类检查时机AlreadyBoundException对已绑定通道调用bind() 一个通道可能通过了JVM的AlreadyBoundException检查,但仍因端口被其他进程占用而收到BindException。 第四章:与SO_REUSEADDR和端口复用的区别4.1常见混淆点许多开发者将AlreadyBoundException与端口复用混淆。 但只要NetworkChannel仍是Java网络编程的基础抽象,AlreadyBoundException就将继续作为状态安全的守门人存在。
return3.14*r*r; } } ---- packagecom.same.demo03; importjava.net.MalformedURLException; importjava.rmi.AlreadyBoundException RemoteException e) { e.printStackTrace(); }catch(MalformedURLExceptione) { e.printStackTrace(); }catch(AlreadyBoundException
com.sun.jndi.rmi.registry.ReferenceWrapper; import javax.naming.NamingException; import javax.naming.Reference; import java.rmi.AlreadyBoundException public class jndi { public static void main(String[] args) throws NamingException, RemoteException, AlreadyBoundException com.sun.jndi.rmi.registry.ReferenceWrapper; import javax.naming.NamingException; import javax.naming.Reference; import java.rmi.AlreadyBoundException class server { public static void main(String[] args) throws RemoteException, NamingException, AlreadyBoundException
this.password = password; } } 3.3服务器类 package cn.com.tt.rmiserver.entry; import java.rmi.AlreadyBoundException cn.com.tt.rmiserver.stub.UserManagerInterface; public class Entry { public static void main(String []args) throws AlreadyBoundException
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Proxy; import java.rmi.AlreadyBoundException , InvocationTargetException, InstantiationException, ClassNotFoundException, NoSuchMethodException, AlreadyBoundException import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Proxy; import java.rmi.AlreadyBoundException , InvocationTargetException, InstantiationException, ClassNotFoundException, NoSuchMethodException, AlreadyBoundException
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Proxy; import java.rmi.AlreadyBoundException , InvocationTargetException, InstantiationException, ClassNotFoundException, NoSuchMethodException, AlreadyBoundException import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Proxy; import java.rmi.AlreadyBoundException , InvocationTargetException, InstantiationException, ClassNotFoundException, NoSuchMethodException, AlreadyBoundException
obj; } } public void bind(String name, Remote obj) throws RemoteException, AlreadyBoundException = null) throw new AlreadyBoundException(name); bindings.put(name, obj);
isOpen()) throw new ClosedChannelException(); if (isBound()) throw new AlreadyBoundException
. */ importjava.net.MalformedURLException; importjava.rmi.AlreadyBoundException; importjava.rmi.Naming ; e.printStackTrace(); }catch(AlreadyBoundException e) { System.out.println("发生重复绑定对象异常!")
ServerTest { public static void main(String[] args) throws RemoteException, MalformedURLException, AlreadyBoundException ; } } 启动方法: public class Run { public static void main(String[] args) throws IOException, AlreadyBoundException
AclNotFoundException, ActivationException, AlreadyBoundException, ApplicationException, AWTException,
; } } A 启动类 package com.xiaoliuliu.a; import java.rmi.AlreadyBoundException; import java.rmi.RemoteException HelloServiceImpl()); } catch (RemoteException e) { e.printStackTrace(); } catch (AlreadyBoundException
package pers.rmi; import java.net.MalformedURLException; import java.rmi.AlreadyBoundException; import RemoteServer { public static void main(String[] args) throws RemoteException, MalformedURLException, AlreadyBoundException
; e.printStackTrace(); } catch (AlreadyBoundException e) {
服务类 Server.java package angle_proxyPattern2; import java.net.MalformedURLException; import java.rmi.AlreadyBoundException ; e.printStackTrace(); }catch(AlreadyBoundException e) { System.out.println("发生重复绑定对象异常!")
; e.printStackTrace(); } catch (AlreadyBoundException e) { System.out.println
服务类 Server.java package angle_proxyPattern2; import java.net.MalformedURLException; import java.rmi.AlreadyBoundException ; e.printStackTrace(); }catch(AlreadyBoundException e) { System.out.println("发生重复绑定对象异常!")
return "Server"; }} 服务端测试程序 Server.java: import java.net.MalformedURLException;import java.rmi.AlreadyBoundException e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (AlreadyBoundException
; e.printStackTrace(); } catch (AlreadyBoundException e) { System.out.println