mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
close ServerSocket instance in finally block
This commit is contained in:
@@ -40,19 +40,22 @@ public class NetUtils {
|
||||
|
||||
public static int findAvailableSocketPort() throws IOException {
|
||||
final ServerSocket serverSocket = new ServerSocket(0);
|
||||
int port = serverSocket.getLocalPort();
|
||||
//workaround for linux : calling close() immediately after opening socket
|
||||
//may result that socket is not closed
|
||||
synchronized(serverSocket) {
|
||||
try {
|
||||
serverSocket.wait(1);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOG.error(e);
|
||||
try {
|
||||
int port = serverSocket.getLocalPort();
|
||||
//workaround for linux : calling close() immediately after opening socket
|
||||
//may result that socket is not closed
|
||||
synchronized (serverSocket) {
|
||||
try {
|
||||
serverSocket.wait(1);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
return port;
|
||||
} finally {
|
||||
serverSocket.close();
|
||||
}
|
||||
serverSocket.close();
|
||||
return port;
|
||||
}
|
||||
|
||||
public static int[] findAvailableSocketPorts(int capacity) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user