|
4 | 4 | import java.util.List;
|
5 | 5 | import java.util.HashMap;
|
6 | 6 | import java.util.Map;
|
| 7 | +import java.util.concurrent.ExecutorService; |
| 8 | +import java.util.concurrent.Executors; |
| 9 | +import java.util.concurrent.TimeUnit; |
7 | 10 |
|
8 | 11 | import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
|
9 | 12 | import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
|
@@ -71,6 +74,7 @@ This table must have a Global Secondary Index (GSI) configured named "last4UnitC
|
71 | 74 | public class CompoundBeaconSearchableEncryptionExample {
|
72 | 75 |
|
73 | 76 | static String GSI_NAME = "last4UnitCompound-index";
|
| 77 | + static int MAX_CONCURRENT_QUERY_THREADS = 10; |
74 | 78 |
|
75 | 79 | public static void PutItemQueryItemWithCompoundBeacon(String ddbTableName, String branchKeyId, String branchKeyWrappingKmsKeyArn, String branchKeyDdbTableName) {
|
76 | 80 |
|
@@ -232,6 +236,26 @@ public static void PutItemQueryItemWithCompoundBeacon(String ddbTableName, Strin
|
232 | 236 | .build())
|
233 | 237 | .build();
|
234 | 238 |
|
| 239 | + // Perform PutItem and Query |
| 240 | + PutAndQueryItemWithCompoundBeacon(ddb, ddbTableName); |
| 241 | + |
| 242 | + // If instead you were working in a multi-threaded context |
| 243 | + // it might look like this |
| 244 | + Runnable myThread = () -> { |
| 245 | + for(int i = 0; i < 20; ++i) { |
| 246 | + PutAndQueryItemWithCompoundBeacon(ddb, ddbTableName); |
| 247 | + } |
| 248 | + }; |
| 249 | + ExecutorService pool = Executors.newFixedThreadPool(MAX_CONCURRENT_QUERY_THREADS); |
| 250 | + for(int i = 0; i < (2*MAX_CONCURRENT_QUERY_THREADS); i++) { |
| 251 | + pool.execute(myThread); |
| 252 | + } |
| 253 | + pool.shutdown(); |
| 254 | + try {pool.awaitTermination(30, TimeUnit.SECONDS);} catch (Exception e) {} |
| 255 | + } |
| 256 | + |
| 257 | + public static void PutAndQueryItemWithCompoundBeacon(DynamoDbClient ddb, String ddbTableName) { |
| 258 | + |
235 | 259 | // 11. Put an item with both attributes used in the compound beacon.
|
236 | 260 | final HashMap<String, AttributeValue> item = new HashMap<>();
|
237 | 261 | item.put("work_id", AttributeValue.builder().s("9ce39272-8068-4efd-a211-cd162ad65d4c").build());
|
|
0 commit comments