Reputation: 951
What is the best way using RMI over tomcat?
Can i create global RMI-pool or one RMI connection for all my applications?
Upvotes: 1
Views: 1107
Reputation: 21
Sample 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;
}
}
Sample 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);
}
}
}
}
Upvotes: 1
Reputation: 20969
I use a static class in a controller that wraps the RMI interface. RMI will pool your connections on the serverside, you don't need to worry about it in your Tomcat.
Upvotes: 1