10 threads are agreed upon when the Client connects to the server, when the Client asks for a word, the server wakes up these threads and they will go through a list of tasks.
What I wanted to happen: whenever a thread scans () that word, remove that task from the list so that when the next one ran that task it was not already on the list.
What happens: more than one thread starts scanning (), and all scan () the first task.
public class ThreadSearcher extends Thread{
private int x;
public ThreadSearcher(int x){
this.x=x;
}
@Override
public void run(){
while(!interrupted()){
System.out.println("Comecei a correr:" + x);
try {
Tarefa t = getTarefas().get(0);
scan(t);
System.out.println("Sou a "+ this.x + " e fiz o scan de " + t.getStart() + "a" + t.getFinish());
System.out.println("Sou a " + x + "antes de remover tinha " + tarefas.size());
tarefas.remove(t);
System.out.println("Sou a " + x + "depois de remover tinha " + tarefas.size());
System.out.println("removi a" + t);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}