Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

Commit 1293885

Browse files
author
Theo van Kraay
committed
add comments for async
1 parent f2439de commit 1293885

2 files changed

Lines changed: 32 additions & 19 deletions

File tree

src/main/java/com/azure/cosmos/examples/documentcrud/async/DocumentCRUDQuickstartAsync.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public class DocumentCRUDQuickstartAsync {
5252
private AtomicBoolean createDocDone = new AtomicBoolean(false);
5353
private AtomicBoolean createDocsDone = new AtomicBoolean(false);
5454

55-
private AtomicBoolean readDocDone = new AtomicBoolean(false);
56-
5755
private List<JsonNode> jsonList;
5856
private String etag1;
5957
private String etag2;
@@ -135,8 +133,8 @@ private void documentCRUDDemo() throws Exception {
135133
createDocuments(familiesToCreate);
136134

137135
while (!(createDocDone.get() && createDocsDone.get())) {
138-
//waiting for async createDoc and createDocs to complete...
139-
logger.info("waiting for async createDoc and createDocs to complete...");
136+
// We are adding Thread.sleep to mimic the some business computation that can
137+
// happen while waiting for earlier processes to finish.
140138
Thread.sleep(100);
141139
}
142140

@@ -149,8 +147,8 @@ private void documentCRUDDemo() throws Exception {
149147

150148
getDocumentsAsJsonArray();
151149
while (this.jsonList == null) {
152-
//wait for jsonList to be set
153-
logger.info("waiting in while (this.jsonList == null) {");
150+
// We are adding Thread.sleep to mimic the some business computation that can
151+
// happen while waiting for earlier processes to finish.
154152
Thread.sleep(100);
155153
}
156154
//convert jsonList to ArrayNode
@@ -159,7 +157,8 @@ private void documentCRUDDemo() throws Exception {
159157
replaceDocument();
160158
upsertDocument();
161159
while (!(upsertDone.get() && replaceDone.get())) {
162-
logger.info("waiting for async upsert and replace to complete...");
160+
// We are adding Thread.sleep to mimic the some business computation that can
161+
// happen while waiting for earlier processes to finish.
163162
Thread.sleep(100);
164163
}
165164
logger.info("replace and upsert done now...");
@@ -404,7 +403,8 @@ private void replaceDocumentWithConditionalEtagCheck() throws Exception {
404403
}).subscribe();
405404

406405
while (this.etag1 == null) {
407-
logger.info("waiting until we got the etag1 from the first read....");
406+
// We are adding Thread.sleep to mimic the some business computation that can
407+
// happen while waiting for earlier processes to finish.
408408
Thread.sleep(100);
409409
}
410410
String etag = this.etag1;
@@ -430,7 +430,9 @@ private void replaceDocumentWithConditionalEtagCheck() throws Exception {
430430

431431

432432
while (updateEtagDone.get() == false) {
433-
//wait until update done
433+
// We are adding Thread.sleep to mimic the some business computation that can
434+
// happen while waiting for earlier processes to finish.
435+
Thread.sleep(100);
434436
}
435437
// Now update the document and call replace with the AccessCondition requiring that ETag has not changed.
436438
// This should fail because the "concurrent" document change updated the ETag.
@@ -471,12 +473,13 @@ private void readDocumentOnlyIfChanged() throws Exception {
471473
}).subscribe();
472474

473475
while (this.etag2 == null) {
474-
logger.info("waiting until we got the etag2 from the first read....");
476+
// We are adding Thread.sleep to mimic the some business computation that can
477+
// happen while waiting for earlier processes to finish.
475478
Thread.sleep(100);
476479
}
477480
while (this.isFamily2Updated.get() == false) {
478-
//wait for family to be upadted...
479-
logger.info("waiting until family2 got updated....");
481+
// We are adding Thread.sleep to mimic the some business computation that can
482+
// happen while waiting for earlier processes to finish.
480483
Thread.sleep(100);
481484
}
482485
;
@@ -501,7 +504,8 @@ private void readDocumentOnlyIfChanged() throws Exception {
501504
.subscribe();
502505

503506
while (reReadDone.get() == false) {
504-
//wait for reRead
507+
// We are adding Thread.sleep to mimic the some business computation that can
508+
// happen while waiting for earlier processes to finish.
505509
Thread.sleep(100);
506510
}
507511
// Replace the doc with a modified version, which will update ETag
@@ -521,7 +525,9 @@ private void readDocumentOnlyIfChanged() throws Exception {
521525
}).subscribe();
522526

523527
while (secondUpdateDone.get() == false) {
524-
//wait for second update before re-reading the doc...
528+
// We are adding Thread.sleep to mimic the some business computation that can
529+
// happen while waiting for earlier processes to finish.
530+
Thread.sleep(100);
525531
}
526532

527533
// Re-read doc again, with conditional access requirements.

src/main/java/com/azure/cosmos/examples/queries/async/QueriesQuickstartAsync.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ private void queriesDemo() throws Exception {
111111
createDocument();
112112

113113
while (creatDocComplete.get() == false){
114-
//waiting for async create doc...
114+
// We are adding Thread.sleep to mimic the some business computation that can
115+
// happen while waiting for earlier processes to finish.
116+
Thread.sleep(100);
115117
}
116118
logger.info("Async doc create done.");
117119

@@ -130,15 +132,20 @@ private void queriesDemo() throws Exception {
130132
queryWithQuerySpec();
131133
parallelQueryWithPagingAndContinuationTokenAndPrintQueryCharge();
132134

133-
//waiting for executeQueryPrintSingleResult to finish
134135
while (executeQueryPrintSingleResultNumber.get()<15){
135-
// can do some other processing here if required
136+
// We are adding Thread.sleep to mimic the some business computation that can
137+
// happen while waiting for earlier processes to finish.
138+
Thread.sleep(100);
136139
}
137140
while (executeCountQueryPrintSingleResultNumber.get()<2){
138-
// can do some other processing here if required
141+
// We are adding Thread.sleep to mimic the some business computation that can
142+
// happen while waiting for earlier processes to finish.
143+
Thread.sleep(100);
139144
}
140145
while (executeQueryWithQuerySpecPrintSingleResultNumber.get()<2){
141-
// can do some other processing here if required
146+
// We are adding Thread.sleep to mimic the some business computation that can
147+
// happen while waiting for earlier processes to finish.
148+
Thread.sleep(100);
142149
}
143150
logger.info("*********Finished waiting - all async queries complete.");
144151

0 commit comments

Comments
 (0)