This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new ea60c36664 Remove unnecessary syncs.
ea60c36664 is described below
commit ea60c366643387135d837707a21cf262944bdfd0
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Sep 17 08:50:14 2025 +0100
Remove unnecessary syncs.
Result of review of an issue reported by Coverity.
---
.../catalina/tribes/transport/nio/NioSender.java | 47 +++++++++++-----------
1 file changed, 23 insertions(+), 24 deletions(-)
diff --git a/java/org/apache/catalina/tribes/transport/nio/NioSender.java
b/java/org/apache/catalina/tribes/transport/nio/NioSender.java
index 4fd964223e..c0cd7f7333 100644
--- a/java/org/apache/catalina/tribes/transport/nio/NioSender.java
+++ b/java/org/apache/catalina/tribes/transport/nio/NioSender.java
@@ -33,8 +33,8 @@ import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
/**
- * This class is NOT thread safe and should never be used with more than one
thread at a time This is a state machine,
- * handled by the process method States are:
+ * This class is NOT thread safe and should never be used with more than one
thread at a time. This is a state machine,
+ * handled by the process method. States are:
* <ul>
* <li>NOT_CONNECTED -> connect() -> CONNECTED</li>
* <li>CONNECTED -> setMessage() -> READY TO WRITE</li>
@@ -42,6 +42,7 @@ import org.apache.juli.logging.LogFactory;
* <li>READY_TO_READ -> read() -> READY_TO_READ | TRANSFER_COMPLETE</li>
* <li>TRANSFER_COMPLETE -> CONNECTED</li>
* </ul>
+ * Thread-safety / synchronisation is managed by ParallelNioSender
*/
public class NioSender extends AbstractSender {
@@ -220,7 +221,7 @@ public class NioSender extends AbstractSender {
}
@Override
- public synchronized void connect() throws IOException {
+ public void connect() throws IOException {
if (connecting || isConnected()) {
return;
}
@@ -357,28 +358,26 @@ public class NioSender extends AbstractSender {
public void setMessage(byte[] data, int offset, int length) throws
IOException {
if (data != null) {
- synchronized (this) {
- current = data;
- remaining = length;
- ackbuf.clear();
- if (writebuf != null) {
- writebuf.clear();
- } else {
- writebuf = getBuffer(length);
- }
- if (writebuf.capacity() < length) {
- writebuf = getBuffer(length);
- }
+ current = data;
+ remaining = length;
+ ackbuf.clear();
+ if (writebuf != null) {
+ writebuf.clear();
+ } else {
+ writebuf = getBuffer(length);
+ }
+ if (writebuf.capacity() < length) {
+ writebuf = getBuffer(length);
+ }
- // TODO use ByteBuffer.wrap to avoid copying the data.
- writebuf.put(data, offset, length);
- writebuf.flip();
- if (isConnected()) {
- if (isUdpBased()) {
- dataChannel.register(getSelector(),
SelectionKey.OP_WRITE, this);
- } else {
- socketChannel.register(getSelector(),
SelectionKey.OP_WRITE, this);
- }
+ // TODO use ByteBuffer.wrap to avoid copying the data.
+ writebuf.put(data, offset, length);
+ writebuf.flip();
+ if (isConnected()) {
+ if (isUdpBased()) {
+ dataChannel.register(getSelector(), SelectionKey.OP_WRITE,
this);
+ } else {
+ socketChannel.register(getSelector(),
SelectionKey.OP_WRITE, this);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]