2011-01-31 2 views
1

바람둥이 이상 RMI를 사용하는 가장 좋은 방법은 무엇입니까?Tomcat + RMI가 가장 좋은 방법일까요?

내 모든 응용 프로그램에 대해 글로벌 RMI 풀 또는 하나의 RMI 연결을 만들 수 있습니까?

+0

. 왜 이런 식으로하고 싶은거야 ..? – water

+0

내 서블릿에서 stanbalone 응용 프로그램의 데이터를 가져와야합니다. – Akvel

답변

1

RMI 인터페이스를 감싸는 컨트롤러에서 정적 클래스를 사용합니다. RMI가 서버 측에 연결을 풀 것이므로 Tomcat에서 걱정할 필요가 없습니다.

1

샘플 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; 
    } 
} 

샘플 서블릿

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); 
} 
    } 
    } 

} 
관련 문제