Fala galera, tudo bem?
Estou começando a ver sobre RMI, e preciso criar uma aplicação que simule um banco. Neste caso estou com dúvidas em como implementar as threads para simular múltiplos clientes acessando o servidor.
Quando realizo acesso com um cliente (que está em uma thread) não tenho problemas, porém, ao tentar acesso com mais clientes(cada um em uma thread) obtenho o seguinte erro:
Exception in thread "Thread-5" Exception in thread "Thread-4" java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "setSecurityManager") at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) at java.security.AccessController.checkPermission(AccessController.java:884) at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) at java.lang.System.setSecurityManager0(System.java:300) at java.lang.System.setSecurityManager(System.java:291) at br.mack.rmi.client.RmiClient.run(RmiClient.java:24) at java.lang.Thread.run(Thread.java:745)
A minha classe cliente está da seguinte forma:
public class RmiClient extends Thread{ private IExemplo exemplo = null;
public void run() {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
try {
Registry registry =
LocateRegistry.getRegistry("localhost");
exemplo = (IExemplo)
registry.lookup("exemplormi");
System.out.println(exemplo.metodo1());
exemplo.metodo2("Client A!");
System.out.println(exemplo.metodo1());
} catch (Exception e) {
if (e instanceof RuntimeException)
throw (RuntimeException) e;
System.out.println("" + e);
}
}
public IExemplo getIExemplo(){
return exemplo;
}
}`
E minha main, assim:
public class RmiTeste {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Inicio de teste...");
RmiClient cliente1 = new RmiClient();
RmiClient cliente2 = new RmiClient();
RmiClient cliente3 = new RmiClient();
Thread t1 = new Thread(cliente1);
t1.start();
Thread t2 = new Thread(cliente2);
t2.start();
Thread t3 = new Thread(cliente3);
t3.start();
}
}
`
Alguém poderia me ajudar nesta questão?
Muito obrigado!!