import java.io.IOException;
import java.net.ServerSocket;
import java.util.List;
-import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;
}
public Future<?> connect() throws IOException {
- return executorService.submit(new Callable<Void>() {
- @Override
- public Void call() throws Exception {
- clientSocket.set(new TextSocket(serverSocket.accept()));
- return null;
- }
+ return executorService.submit(() -> {
+ clientSocket.set(new TextSocket(serverSocket.accept()));
+ return null;
});
}
@Override
public void close() throws IOException {
- clientSocket.get().close();
+ TextSocket textSocket = clientSocket.get();
+ if (textSocket != null) {
+ textSocket.close();
+ }
}
}