RMI calls in CompletableFuture stream

is it safe to call rmi service using CompletableFuture like so
Registry registry = null;
        try {
            // Locate the RMI registry and obtain a reference to the remote object
            registry = LocateRegistry.getRegistry("your_server_hostname", 1099);
        } catch (Exception e) {
            e.printStackTrace();
        }
        PersonService personService = (PersonService) registry.lookup("PersonService");
        // Use CompletableFuture to perform RMI calls in parallel
        List<Person> lastNameFutures = personList.stream()
                .map(person -> CompletableFuture.supplyAsync(() -> { 
          person.setCompletableName(personService.getLastName(person)
          return person;
}
), executorService))
                .collect(Collectors.toList());

Notice i am mutating person object and saving future in Person
Was this page helpful?