0
I started to study tread I saw some examples of java7 and java8 ultilizando lambda, I arrived in part to ultiliza the Synchronized that and to leave kind a wait list of threads where the next one is executed after a finished, I’m testing but I’m not able to run multithreading what I’m doing wrong? the output of the code should be first the T1 then the T2 and finally the T3 but it numca follows the result of when finish a go to the next.
public class mainThread {
public synchronized void imprimirValores(String numeroThread) {
for (int i = 0; i < 20; i++)
System.out.println(numeroThread + " : " + i);
}
public static void main(String[] args) {
new Thread(() -> {
new mainThread().imprimirValores("T1");
}).start();
new Thread(() -> {
new mainThread().imprimirValores("T2");
}).start();
new Thread(() -> {
new mainThread().imprimirValores("T3");
}).start();
}
}
I thought your answer was flawed in the diversity of solution to the problem, so I made the counterpoint focusing only on this point. Otherwise, she is very good.
– Jefferson Quesado
Thank you test here and ran the book I was reading had almost nothing explanation just talked to use the word Synchronized
– Fernando josé