Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Re-entrant locks instead of synchronized blocks to make driver loom friendly #2328

Closed
wants to merge 9 commits into from
69 changes: 52 additions & 17 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1440,8 +1440,13 @@ public int getPort() {
}

@Override
public synchronized int getReceiveBufferSize() throws SocketException {
return tdsChannel.tcpSocket.getReceiveBufferSize();
public int getReceiveBufferSize() throws SocketException {
tdsChannelLock.lock();
try {
return tdsChannel.tcpSocket.getReceiveBufferSize();
} finally {
tdsChannelLock.unlock();
}
}

@Override
Expand All @@ -1455,8 +1460,13 @@ public boolean getReuseAddress() throws SocketException {
}

@Override
public synchronized int getSendBufferSize() throws SocketException {
return tdsChannel.tcpSocket.getSendBufferSize();
public int getSendBufferSize() throws SocketException {
tdsChannelLock.lock();
try {
return tdsChannel.tcpSocket.getSendBufferSize();
} finally {
tdsChannelLock.unlock();
}
}

@Override
Expand All @@ -1465,8 +1475,13 @@ public int getSoLinger() throws SocketException {
}

@Override
public synchronized int getSoTimeout() throws SocketException {
return tdsChannel.tcpSocket.getSoTimeout();
public int getSoTimeout() throws SocketException {
tdsChannelLock.lock();
try {
return tdsChannel.tcpSocket.getSoTimeout();
} finally {
tdsChannelLock.unlock();
}
}

@Override
Expand Down Expand Up @@ -1536,21 +1551,36 @@ public void connect(SocketAddress endpoint, int timeout) throws IOException {
// Ignore calls to methods that would otherwise allow the SSL socket
// to directly manipulate the underlying TCP socket
@Override
public synchronized void close() throws IOException {
if (logger.isLoggable(Level.FINER))
logger.finer(logContext + " Ignoring close");
public void close() throws IOException {
tdsChannelLock.lock();
try {
if (logger.isLoggable(Level.FINER))
logger.finer(logContext + " Ignoring close");
} finally {
tdsChannelLock.unlock();
}
}

@Override
public synchronized void setReceiveBufferSize(int size) throws SocketException {
if (logger.isLoggable(Level.FINER))
logger.finer(toString() + " Ignoring setReceiveBufferSize size:" + size);
public void setReceiveBufferSize(int size) throws SocketException {
tdsChannelLock.lock();
try {
if (logger.isLoggable(Level.FINER))
logger.finer(toString() + " Ignoring setReceiveBufferSize size:" + size);
} finally {
tdsChannelLock.unlock();
}
}

@Override
public synchronized void setSendBufferSize(int size) throws SocketException {
if (logger.isLoggable(Level.FINER))
logger.finer(toString() + " Ignoring setSendBufferSize size:" + size);
public void setSendBufferSize(int size) throws SocketException {
tdsChannelLock.lock();
try {
if (logger.isLoggable(Level.FINER))
logger.finer(toString() + " Ignoring setSendBufferSize size:" + size);
} finally {
tdsChannelLock.unlock();
}
}

@Override
Expand All @@ -1566,8 +1596,13 @@ public void setSoLinger(boolean on, int linger) throws SocketException {
}

@Override
public synchronized void setSoTimeout(int timeout) throws SocketException {
tdsChannel.tcpSocket.setSoTimeout(timeout);
public void setSoTimeout(int timeout) throws SocketException {
tdsChannelLock.lock();
try {
tdsChannel.tcpSocket.setSoTimeout(timeout);
} finally {
tdsChannelLock.unlock();
}
}

@Override
Expand Down
Loading