Skip to content

Commit

Permalink
去掉synchronized
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Mar 17, 2016
1 parent d294227 commit 3cb3f3f
Showing 1 changed file with 19 additions and 38 deletions.
57 changes: 19 additions & 38 deletions lealone-net/src/main/java/org/lealone/net/AsyncConnection.java
Expand Up @@ -391,10 +391,7 @@ private void executeQuery(Session session, int id, PreparedStatement command, in
PreparedCommand pc = new PreparedCommand(command, session, new Callable<Object>() {
@Override
public Object call() throws Exception {
Result result;
synchronized (session) {
result = command.query(maxRows, false);
}
final Result result = command.query(maxRows, false);
cache.addObject(objectId, result);

Response response = new Response(new Callable<Object>() {
Expand Down Expand Up @@ -436,10 +433,7 @@ private void executeUpdate(Session session, int id, PreparedStatement command, i
PreparedCommand pc = new PreparedCommand(command, session, new Callable<Object>() {
@Override
public Object call() throws Exception {
int updateCount;
synchronized (session) {
updateCount = command.update();
}
int updateCount = command.update();
int status;
if (session.isClosed()) {
status = Session.STATUS_CLOSED;
Expand Down Expand Up @@ -710,10 +704,9 @@ private void process() throws IOException {
StorageMap<Object, Object> map = session.getStorageMap(mapName);

DataType valueType = map.getValueType();
// synchronized (session) {
Object result = map
.put(map.getKeyType().read(ByteBuffer.wrap(key)), valueType.read(ByteBuffer.wrap(value)));
// }
Object k = map.getKeyType().read(ByteBuffer.wrap(key));
Object v = valueType.read(ByteBuffer.wrap(value));
Object result = map.put(k, v);
int status;
if (session.isClosed()) {
status = Session.STATUS_CLOSED;
Expand Down Expand Up @@ -745,9 +738,7 @@ private void process() throws IOException {
StorageMap<Object, Object> map = session.getStorageMap(mapName);

DataType valueType = map.getValueType();
// synchronized (session) {
Object result = map.get(map.getKeyType().read(ByteBuffer.wrap(key)));
// }

int status;
if (session.isClosed()) {
Expand Down Expand Up @@ -832,9 +823,7 @@ private void process() throws IOException {
}
case Session.COMMAND_DISTRIBUTED_TRANSACTION_COMMIT: {
int old = session.getModificationId();
synchronized (session) {
session.commit(false, transfer.readString());
}
session.commit(false, transfer.readString());
int status;
if (session.isClosed()) {
status = Session.STATUS_CLOSED;
Expand All @@ -847,9 +836,7 @@ private void process() throws IOException {
}
case Session.COMMAND_DISTRIBUTED_TRANSACTION_ROLLBACK: {
int old = session.getModificationId();
synchronized (session) {
session.rollback();
}
session.rollback();
int status;
if (session.isClosed()) {
status = Session.STATUS_CLOSED;
Expand All @@ -864,12 +851,10 @@ private void process() throws IOException {
case Session.COMMAND_DISTRIBUTED_TRANSACTION_ROLLBACK_SAVEPOINT: {
int old = session.getModificationId();
String name = transfer.readString();
synchronized (session) {
if (operation == Session.COMMAND_DISTRIBUTED_TRANSACTION_ADD_SAVEPOINT)
session.addSavepoint(name);
else
session.rollbackToSavepoint(name);
}
if (operation == Session.COMMAND_DISTRIBUTED_TRANSACTION_ADD_SAVEPOINT)
session.addSavepoint(name);
else
session.rollbackToSavepoint(name);
int status;
if (session.isClosed()) {
status = Session.STATUS_CLOSED;
Expand Down Expand Up @@ -901,12 +886,10 @@ private void process() throws IOException {
for (int i = 0; i < size; i++) {
String sql = transfer.readString();
PreparedStatement command = session.prepareStatement(sql, -1);
synchronized (session) {
try {
result[i] = command.update();
} catch (Exception e) {
result[i] = Statement.EXECUTE_FAILED;
}
try {
result[i] = command.update();
} catch (Exception e) {
result[i] = Statement.EXECUTE_FAILED;
}
}
writeBatchResult(result, old);
Expand All @@ -927,12 +910,10 @@ private void process() throws IOException {
CommandParameter p = params.get(j);
p.setValue(transfer.readValue());
}
synchronized (session) {
try {
result[i] = command.update();
} catch (Exception e) {
result[i] = Statement.EXECUTE_FAILED;
}
try {
result[i] = command.update();
} catch (Exception e) {
result[i] = Statement.EXECUTE_FAILED;
}
}
writeBatchResult(result, old);
Expand Down

0 comments on commit 3cb3f3f

Please sign in to comment.