Witam, potrafię uruchomić wątku w tym kodzie
/**
*
* @author Wieczorek Krzysztof S15877
*
*/
package zad1;
public class Main {
public static void main(String[] args) throws InterruptedException {
Letters letters = new Letters("ABCD");
for (Thread t : letters.getThreads()) System.out.println(t.getName());
for (Thread t : letters.threads) {
t.start();
}
/*<- tu uruchomić
wszystkie kody w wÄ…tkach
*/
Thread.sleep(5000);
// for (Thread t : letters.getThreads()){
// t.interrupt();
// }
/*<- tu trzeba zapisać
fragment, który kończy działanie kodów, wypisujących litery
*/
System.out.println("\nProgram skończył działanie");
}
}
package zad1;
import java.util.ArrayList;
public class Letters implements Runnable {
public ArrayList<Thread> threads = new ArrayList<Thread>();
private ArrayList<String> znaki = new ArrayList<String>();
public Letters(String string) {
for(int i = 0; i < string.length(); i++){
String leter = string.substring(i, i+1);
znaki.add(leter);
threads.add(new Thread("Thread " + leter));
}
}
public ArrayList<Thread> getThreads() {
// TODO Auto-generated method stub
return threads;
}
public void run() {
System.out.println("a");
}
}
Dlaczego nie wyświetla mi tego "a"