Код: Выделить всё
class Notif {
public int found;
public String reply;
public Notif(int i){
found = i;
}
}
Код: Выделить всё
Notif[] notif = new Notif[] {new Notif(0)};
Код: Выделить всё
Thread tS = new Thread(new InputSearch(input, notif, neighbors, selfNum)); tS.start();
Код: Выделить всё
notif[0].reply = "File " + msgs[i].fName + " found in " + msgs[i].Cx + ". - Computer " + nums.get(i);
notif[0].found = 1;
System.out.println("found w");
Код: Выделить всё
while(System.currentTimeMillis() - start < hopCt*2000) {
if(notif[0].found != 0){
System.out.println("found n");
replies.add(notif[0].reply);
notif[0].found = 0;
}
}
if(replies.size() == 0)
System.out.println("No replies in " + hopCt*2 + " seconds.");
Я ожидаю, что появятся оба найденных w и найденных n, а также сообщение «Нет ответов за x секунд». не печатается.
Код: Выделить всё
notif.reply
Подробнее здесь: https://stackoverflow.com/questions/789 ... ain-thread