import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
public class ReliableSocketWrapper implements AutoCloseable {
private final Socket socket;
private static final int MAX_RETRIES = 3;
private static final int RETRY_DELAY_MS = 100;
public ReliableSocketWrapper(String host, int port) throws IOException {
this.socket = new Socket(host, port);
}
public Socket getSocket() {
return socket;
}
@Override
public void close() throws IOException {
int attempts = 0;
boolean closed = false;
while (attempts < MAX_RETRIES && !closed) {
try {
if (socket != null && !socket.isClosed()) {
socket.close();
}
closed = true;
} catch (IOException e) {
attempts++;
System.err.println("Failed to close socket, attempt " + attempts + ": " + e.getMessage());
if (attempts >= MAX_RETRIES) {
throw new IOException("Failed to close socket after " + MAX_RETRIES + " attempts", e);
}
try {
Thread.sleep(RETRY_DELAY_MS);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted during close retry", ie);
}
}
}
}
}public void communicate() {
try (ReliableSocketWrapper wrappedSocket = new ReliableSocketWrapper("localhost", 8080)) {
Socket s = wrappedSocket.getSocket();
// Use s to read/write
} catch (IOException e) {
e.printStackTrace();
}
// close() is automatically called, with retries if necessary
}
$() как вы предпочитаете
cat /proc/41257/comm | xargs kill илиcat /proc/41257/comm | xargs -IX kill X
stat() the file (fetch permissions, owner, size, time, etc.).
legacy SQL unavailable in golang?
```
CREATE TEMPORARY TABLE filter_values (
field_1 INT,
field_2 VARCHAR(100)
);
INSERT INTO filter_values VALUES
(1,'a'),
(2,'b'),
(3,'c');
// can do arbitrary array in one call presumably
SELECT t.*
FROM tbl t
JOIN filter_values f
ON t.field_1 = f.field_1
AND t.field_2 = f.field_2;
```