【问题标题】:Tomcat + RMI best way?Tomcat + RMI 最好的方法?
【发布时间】:2011-01-31 12:02:39
【问题描述】:

在 tomcat 上使用 RMI 的最佳方式是什么?

我可以为我的所有应用程序创建全局 RMI 池或一个 RMI 连接吗?

【问题讨论】:

  • 。你为什么要这样做..?
  • 我需要从我的 servlet 中的 stanbalone 应用程序获取数据

标签: java tomcat rmi


【解决方案1】:

我在封装了 RMI 接口的控制器中使用了一个静态类。 RMI 将在服务器端汇集您的连接,您无需在 Tomcat 中担心它。

【讨论】:

    【解决方案2】:

    RMI 示例

    public interface Account 
              extends java.rmi.Remote { 
        public double balance(int accountNumber) 
            throws java.rmi.RemoteException; 
    
    } 
    
    public class AccountImpl 
        extends 
          java.rmi.server.UnicastRemoteObject 
        implements Account { 
     public AccountImpl() 
            throws java.rmi.RemoteException { 
            super(); 
        } 
    
        public double add(int accountNumber) 
            throws java.rmi.RemoteException { 
            return 1000.0; 
        } 
    }
    

    示例 Servlet

    public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException 
    {
    
    Account service=request.getSession()!=null ?(Account)request.getSession().getAttribute(loginService.ACCOUNT_SERVICE.name()):null;
    
    service=service!=null?service:getService();
    if(service!=null)
    {
    request.getSession().setAttribute(loginService.ACCOUNT_SERVICE.name(), service);
    }
        }
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-10-08
      • 2011-08-18
      • 1970-01-01
      • 1970-01-01
      • 2011-12-26
      • 2016-07-05
      • 1970-01-01
      • 2014-01-25
      • 2015-12-21
      相关资源
      最近更新 更多