• Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronized question  RSS feed

 
Sireesh Ganagam
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have a synchronized block in a class like below, does this lock will happen at once class instances or across all class instances?


synchronized (this)// First process the bunch of Asn records then allow second thread
{

createNewTrans(m);

}

Thanks,
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot have such a synchronised block in a class, but in an instance method/constructor. Work out which object holds the lock; then you should be able to work out the answer to your question.
 
Anurag Verma
Ranch Hand
Posts: 170
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Single instance (this) only.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!