package pl.codegym.task.task16.task1603;
import java.util.ArrayList;
import java.util.List;
/*
Lista i kilka wątków
*/
public class Solution {
public static volatile List<Thread> list = new ArrayList<>(5);
public static void main(String[] args)
{
SpecialThread specialThread1 = new SpecialThread();
SpecialThread specialThread2 = new SpecialThread();
SpecialThread specialThread3 = new SpecialThread();
SpecialThread specialThread4 = new SpecialThread();
SpecialThread specialThread5 = new SpecialThread();
Thread thread1 = new Thread(specialThread1);
Thread thread2 = new Thread(specialThread2);
Thread thread3 = new Thread(specialThread3);
Thread thread4 = new Thread(specialThread4);
Thread thread5 = new Thread(specialThread5);
list.add(thread1);
list.add(thread2);
list.add(thread3);
list.add(thread4);
list.add(thread5);
thread1.start();
thread2.start();
thread3.start();
thread4.start();
thread5.start();
}
public static class SpecialThread implements Runnable {
public void run() {
System.out.println("To jest metoda run wewnątrz SpecialThread");
}
}
}
What is wrong?
Rozwiązane
Komentarze (3)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Tomasz Sknadaj
20 lipca 2020, 16:05
I don't get it. I make very similar code and i didn't pass verification on the same task.
Each thread works with his own SpecialThread object, so what's the problem? 0
Nouser
4 maja 2020, 09:52rozwiązanie
I've commented out my start() calls... maybe that's the problem, I don't remember.
+1
Piotr Skuza
4 maja 2020, 13:08
Thanks, as I commented on start () it worked :)
0