Skip to content

Commit af5a677

Browse files
committed
concurrent graph walking
1 parent 0da3a6c commit af5a677

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

mug/src/main/java/com/google/mu/util/graph/find_path_in_graph.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ By using the `visitedUrls` from each page's url, we can still detect already vis
106106

107107
Problem solved.
108108

109+
## Concurrent Graph Walking
110+
111+
With IO (calling the WebPageUrlService) being the bottleneck, it may make sense to crawl the pages
112+
concurrently, as long as the service tolerates the extra load.
113+
114+
To make the code thread safe, we need to create a concurrent `Set<String>` (using `ConcurrentHashSet.newKeySet()`).
115+
Each thread can then create their own Walker instance. The concurrent set will ensure that no two threads
116+
will attempt to visit the same url.
117+
109118
---
110119

111120
## Traverser

0 commit comments

Comments
 (0)