File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Regarding Threads!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding Threads!!" Watch "Regarding Threads!!" New topic
Author

Regarding Threads!!

Ravi Kumar Ravuru
Ranch Hand

Joined: Apr 18, 2002
Posts: 176
Hello Folks,
public class A
{
public static synchroized m1(){
//first thread is created which calls start method
}
public synchroized m2(){
//second thread is created which calls start method
}
public static void main(String args[]){
A a1=new A1():
a1.m1():
A.m2();
}
public void run(){
//some code
}
}
If both methods are called,whether the two threads run simultaneously or one after another.Please help me out.
Regards,
Ravi
Mahesh swami
Greenhorn

Joined: Aug 13, 2002
Posts: 26
Both the threads will be started simultaneously since one method is static it is synchronization for class level. And the Instance method is synchronization for instance level
-Mahesh
Ravi Kumar Ravuru
Ranch Hand

Joined: Apr 18, 2002
Posts: 176
Hello Mahesh,
Please elaborate ur statement.
Regards,
Ravi
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
I think that there are two monitors: one for the class, one for the object. So, it is probable - though not guaranteed - that two threads will start at about the same time, with one thread owning the class monitor and the other owing the object monitor. Ownership of a monitor is obtained by executing the synchronized method.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Threads!!