Witam. mam taki oto kod:
package paczka;
import java.util.concurrent.CountDownLatch;
public class CountDownLDemo {
class MyThread implements Runnable {
String name;
CountDownLatch latch;
MyThread(CountDownLatch c, String n) {
latch = c;
name = n;
// uruchomienie wątka
new Thread(this).start();
}
public void run() {
for (int i = 0; i < 5; i++) {
synchronized (latch) { // wypisanie aktualnego stany licznika
System.out.println(" " + name + " Stan licznika: "
+ latch.getCount());
// zmniejszenie wartości licznika
latch.countDown();
}
try {
Thread.sleep(10);
} catch (Exception e) {
}
;
}
}
}
public static void main(String[] args) {
// zatrzask zliczający pięćzdarzeń
CountDownLatch cdl = new CountDownLatch(5);
System.out.println("Watek glowny: - START");
new MyThread(cdl, " Watek_A");
new MyThread(cdl, " Watek_B");
try {
// Oczekiwanie na zdarzenia
cdl.await();
} catch (InterruptedException exc) {
System.out.println(exc);
}
// Zdarzenia wystąpiły – koniec oczekiwania
System.out.println("Watek glowny: - GOTOWE");
}
}
W linii 42 mam błąd:
No enclosing instance of type CountDownLDemo is accessible. Must qualify the allocation with an enclosing instance of type
CountDownLDemo (e.g. x.new A() where x is an instance of CountDownLDemo).
który nie za bardzo rozumiem. Może mi ktoś wytłumaczyć co tu jest źle ?