Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATACOUCH-224 - Improve concurrent save/insert, optimistic locking
- Loading branch information
1 parent
117f0d0
commit 811c024
Showing
4 changed files
with
214 additions
and
14 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/integration/java/org/springframework/data/couchbase/core/AsyncUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.springframework.data.couchbase.core; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.*; | ||
|
||
public class AsyncUtils { | ||
|
||
public static void executeConcurrently(int numThreads, Callable<Void> task) throws Exception { | ||
ExecutorService pool = Executors.newFixedThreadPool(numThreads); | ||
|
||
Collection<Callable<Void>> tasks = Collections.nCopies(numThreads, task); | ||
|
||
List<Future<Void>> futures = pool.invokeAll(tasks); | ||
for (Future future : futures) { | ||
future.get(numThreads, TimeUnit.SECONDS); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Why changed like this?
There is no way to upsert document when model has version property.
I think if there is no version property or version value is not set, upsert() should be executed.