Mam dwie klasy implementujące Runnable, uruchamiane w dwóch metodach synchroicznych:
public synchronized void checkIp() throws IOException, InterruptedException{
while (available == false)
{
try { wait();}
catch (InterruptedException e) { }
}
ReadLine r = new ReadLine();
ArrayList<Ip> ipList = r.getIpListFromExcel();
Thread[] watki = new Thread[ipList.size()];
for(int i =0 ; i<ipList.size(); i++){
CommandLine c;
watki[i] = new Thread(c = new CommandLine(ipList.get(i)));
watki[i].setPriority(5);
watki[i].start();
resultList.add(c.getR());
}
public synchronized void createLog(){
while (available == false)
{
try { wait();
} catch (InterruptedException e) { }
}
Log l = new Log(resultList);
Thread t = new Thread(l);
t.start();
available = true;
notifyAll();
}
uruchamiane w taki sposób:
boolean available=true;
public Action(boolean checkIP, boolean createLog) throws IOException, MessagingException, InterruptedException {
this.checkIP = checkIP;
this.createLog = createLog;
checkIp();
createLog();
System.exit(0);
}
Metoda checkIp trwa kilka minut, a musi byc wykonana jako pierwsze. Nie wiem jak wymusic aby metoda createLog poczekała na zakończenie tej pierwszej. Obie metody trzą obiekty implementujące klasy Runanbel.