The problem is that I don't see the effect of synchronizing the block. In Theory, I know it's suppose to lock the block until it's done with the thread it would be processing at the time. When I run the following code with or without the synchronized block, nothing changes, well, at least that's what I think. Basically, How do I make these threads display in an orderly manner? Please clear it up for me, thanks.
public class Threads9 extends Thread{
private String name;
public Threads9(String paramName){
name = paramName;
}
public void run() {
print();
}
private void print() {
synchronized(this){
for(int i = 0;i<10;i++){
System.out.println(name+ " looping");
}
}
}
}
public class Threads9Main{
public static void main(String[] args) {
Threads9 thread1 = new Threads9("Thread1");
Threads9 thread2 = new Threads9("Thread2");
thread1.start();
thread2.start();
}
}