Vous n'avez pas besoin de faire quoi que ce soit de spécial, le framework RMI s'occupe automatiquement de supprimer automatiquement les nouveaux threads. Essayez-le avec le serveur le plus simple possible, vous verrez que chaque fois qu'un nouveau client se connecte, il est toujours en mesure de se connecter à la ligne droite du serveur:
public interface Server extends java.rmi.Remote {
void doIt() throws java.rmi.RemoteException;
}
public class ServerImpl extends java.rmi.server.UnicastRemoteObject implements Server {
public ServerImpl() throws java.rmi.RemoteException {
super();
}
public void doIt() {
System.out.println ("Starting in " + Thread.currentThread().getName());
try { Thread.sleep(10000); } catch(InterruptedException t) {}
System.out.println ("Stopping in " + Thread.currentThread().getName());
}
public static void main (String[] argv) throws Exception {
java.rmi.registry.LocateRegistry.createRegistry(1099);
java.rmi.Naming.rebind ("//localhost/Server", new ServerImpl());
}
}
public class Client {
public static void main(String[] argv) throws Exception {
((Server) java.rmi.Naming.lookup("Server")).doIt();
}
}
Certainement pas 'run()'. Les threads sont démarrés avec 'Thread # start()'. –
oui, juste confus – giozh
OK, maintenant votre thread va démarrer et exécuter la méthode 'run' que vous avez écrasée, ou celle d'un' Runnable' que vous avez passé dans son constructeur. –