File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
Similar Threads
Question from Khalid book
Threads
confused on thread topic
not at all able to understand what is happening in this program
THREADS :PLEASE HELP