public class ethread extends
Thread { int x;
int y;
public static void main(
String []args)
{
ethread et=new ethread();
Thread a=new Thread(et);
Thread b=new Thread(et);
a.start();
b.start();
}
public void run (){
for (int i=0;i<10;i++)
{//line 1
x++;
y++;
System.out.println("x"+x+"y"+y+"CurrentThread"+getName());
}
}
}
the reuslt is like blew what i m not sure is where is the second thread
2:
what if i wish to synchronize it like
synchronize(this){ //after line 1
but it gives me error
any help
x1y1CurrentThreadThread-0
x2y2CurrentThreadThread-0
x3y3CurrentThreadThread-0
x4y4CurrentThreadThread-0
x5y5CurrentThreadThread-0
x6y6CurrentThreadThread-0
x7y7CurrentThreadThread-0
x8y8CurrentThreadThread-0
x9y9CurrentThreadThread-0
x10y10CurrentThreadThread-0