Skip to content

Commit

Permalink
Added lock to avoid executing online learning in multiple threads
Browse files Browse the repository at this point in the history
(related to issue #56)
  • Loading branch information
aecio committed Sep 1, 2016
1 parent a610046 commit c97a574
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/focusedCrawler/link/LinkStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import org.slf4j.Logger;
Expand Down Expand Up @@ -80,6 +81,7 @@ public class LinkStorage extends StorageDefault {
private final BipartiteGraphManager graphManager;
private final OnlineLearning onlineLearning;

private AtomicBoolean onlineLearningIsRunning = new AtomicBoolean(false);
private AtomicInteger numberOfPages = new AtomicInteger(0);
private AtomicInteger numberOfBacklink = new AtomicInteger(0);

Expand Down Expand Up @@ -175,9 +177,13 @@ public Object insert(Page page) throws StorageException {
}

if (onlineLearning != null && numberOfPages % learnLimit == 0) {
logger.info("RUNNING ONLINE LEARNING...");
onlineLearning.execute();
frontierManager.clearFrontier();
if(onlineLearningIsRunning.compareAndSet(false, true)) {
// onlineLearningIsRunning is true
logger.info("RUNNING ONLINE LEARNING...");
onlineLearning.execute();
frontierManager.clearFrontier();
onlineLearningIsRunning.set(false);
}
}

if (getBacklinks) {
Expand Down

0 comments on commit c97a574

Please sign in to comment.