Skip to content

Commit bb55761

Browse files
committed
[spring] Fix postgres deadlock
The now fixed deadlock issue was only visible under high concurrency and was generating errors and leading to lower than expected performance. Sorting the worlds before updating them allows to avoid this issue.
1 parent 4d021bf commit bb55761

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

frameworks/Java/spring/src/main/java/hello/web/DbHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hello.web;
22

33
import java.util.Collections;
4+
import java.util.Comparator;
45
import java.util.List;
56

67
import hello.Utils;
@@ -52,6 +53,7 @@ ServerResponse updates(ServerRequest request) {
5253
world.randomNumber = randomNumber;
5354
return world;
5455
}).limit(queries)
56+
.sorted(Comparator.comparingInt(w -> w.id))
5557
.toList();
5658
dbRepository.updateWorlds(worlds);
5759
return ServerResponse.ok()

0 commit comments

Comments
 (0)