Skip to content

Commit

Permalink
join with a timeout does not cause that the corresponding thread is s…
Browse files Browse the repository at this point in the history
…topped after the time-out. It does only cause that the waiting is stopped. Here we need additionally a signal to the thread to stop after we finished waiting.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6069 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Jun 13, 2009
1 parent b69f22e commit b8bb1bb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions source/de/anomic/tools/DidYouMean.java
Expand Up @@ -26,6 +26,7 @@ public class DidYouMean {
private final IndexCell<WordReference> index;
private String word;
private int len;
private boolean stop;

private Thread ChangingOneLetter;
private Thread AddingOneLetter;
Expand All @@ -38,6 +39,7 @@ public DidYouMean(final IndexCell<WordReference> index) {
this.word = "";
this.len = 0;
this.index = index;
this.stop = false;

this.ChangingOneLetter = new ChangingOneLetter();
this.AddingOneLetter = new AddingOneLetter();
Expand All @@ -61,7 +63,9 @@ public Set<String> getSuggestion(final String word) {
this.ChangingOneLetter.join(TIMEOUT);
this.AddingOneLetter.join(TIMEOUT);
} catch (InterruptedException e) {
}
} finally {
stop = true;
}

this.set.remove(word.toLowerCase());
Log.logInfo("DidYouMean", "found "+this.set.size()+" terms; execution time: "+(System.currentTimeMillis()-startTime)+"ms");
Expand All @@ -82,6 +86,7 @@ public void run() {
set.add(s);
count++;
}
if (stop) return;
}
}
}
Expand All @@ -90,16 +95,17 @@ public void run() {
private class DeletingOneLetter extends Thread {
// tests: len
public void run() {
String s;
int count = 0;
String s;
int count = 0;
for(int i=0; i<len;i++) {
s = word.substring(0, i) + word.substring(i+1);
if (index.has(Word.word2hash(s))) {
set.add(s);
count++;
}
if (stop) return;
}
}
}
}

private class AddingOneLetter extends Thread {
Expand All @@ -114,6 +120,7 @@ public void run() {
set.add(s);
count++;
}
if (stop) return;
}
}
}
Expand All @@ -130,6 +137,7 @@ public void run() {
set.add(s);
count++;
}
if (stop) return;
}
}
}
Expand Down

0 comments on commit b8bb1bb

Please sign in to comment.