Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Junit test for synchronized method

 
Maria Laxmi
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is there a good way to test that a method is synchronized in a JUnit test? I have used synchronized method for J2EE application.

Thanks,
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't you just test it like any other method?
 
Maria Laxmi
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My concern is to test when multiple threads try to call synchronized method at the same time. Is there any way we can catch this scenario in Junit Testcase?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure; set up a bunch of threads and have them call it. But that seems like unit-testing the "synchronized" keyword to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic