Hi all. This is my first post although I have been sucking information from this site for quite a while now. Can anyone tell me why the following program prints the numbers 0-9 in a random order regardless of whether or not the run() method is synchronized. As (I thought) I understood it, synchronized will only give one
Thread object access to the method at a time. I would think that if I used "synchronized" the numbers 0-9 would be printed out in order 4 times. Thanks in advance for your help
public class tosh extends Thread
{
static Thread t1=new tosh();
static Thread t2=new tosh();
static Thread t3=new tosh();
static Thread t4=new tosh();
public static void main(
String [] args)
{
t1.start();
t2.start();
t3.start();
t4.start();
}
public synchronized void run()
{
for (i=0;i<10;i++)
{
System.out.println(i);}
}
}