Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Threads!!

 
Ravi Kumar Ravuru
Ranch Hand
Posts: 176
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 176
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mahesh,
Please elaborate ur statement.
Regards,
Ravi
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic