Skip to content

Commit 1471dd2

Browse files
stIncMalejyemin
authored andcommitted
Join the thread in DocumentationSamples.testWatch (#686)
JAVA-4075
1 parent c5886fb commit 1471dd2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

driver-sync/src/examples/documentation/DocumentationSamples.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,13 @@ public void testDeletions() {
702702
}
703703

704704
@Test
705-
public void testWatch() {
705+
public void testWatch() throws InterruptedException {
706706
assumeTrue(isDiscoverableReplicaSet() && serverVersionAtLeast(3, 6));
707707

708708
final MongoCollection<Document> inventory = collection;
709709
final AtomicBoolean stop = new AtomicBoolean(false);
710710

711-
new Thread(new Runnable() {
711+
Thread thread = new Thread(new Runnable() {
712712
@Override
713713
public void run() {
714714
while (!stop.get()) {
@@ -721,8 +721,8 @@ public void run() {
721721
collection.deleteOne(new Document("username", "alice"));
722722
}
723723
}
724-
}).start();
725-
724+
});
725+
thread.start();
726726

727727
// Start Changestream Example 1
728728
MongoCursor<ChangeStreamDocument<Document>> cursor = inventory.watch().iterator();
@@ -756,6 +756,7 @@ public void run() {
756756
cursor.close();
757757

758758
stop.set(true);
759+
thread.join();
759760
}
760761

761762
@Test

0 commit comments

Comments
 (0)