I started to study tread I saw some examples of java7 and java8 using lambda, I came in a part to use the synchronized which is to type a waiting list of threads where the next one and executed after a finish, I am testing but not I'm getting multithreading running what am I doing wrong? the output of the code should be first to T1 then to T2 and finally to T3 but it does not follow the result of when you finish one go to the next one.
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();
}
}