aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes multi threading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "multi threading" Watch "multi threading" New topic
Author

multi threading

sri rallapalli
Ranch Hand

Joined: Mar 15, 2005
Posts: 88
can anybody please let me know the ans and how for the following code.

public class Myclass extends Thread
{
static Object lok1 = new Object();
static Object lok2 = new Object();
static volatile int i1,i2,j1,j2,k1,k2;
public void run()
{
while(true)
{
doit();
check();
}
}
void doit()
{
synchronized(lok1)
{
i1++;
}
j1++;
synchronized(lok2)
{
k1++;k2++;
}
j2++;
synchronized(lok1)
{
i2++;
}
}
void check()
{
if(i1!=i2) System.out.println("i");
if(j1!=j2) System.out.println("j");
if(k1!=k2) System.out.println("k");
}
public static void main(String arg[])
{
new Myclass().start();
new Myclass().start();
}
}

thanks,
sri.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multi threading