wood burning stoves 2.0*
The moose likes Testing and the fly likes Junit test for synchronized method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Junit test for synchronized method" Watch "Junit test for synchronized method" New topic
Author

Junit test for synchronized method

Maria Laxmi
Ranch Hand

Joined: Aug 08, 2008
Posts: 40
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

Joined: Sep 29, 2008
Posts: 12617

Wouldn't you just test it like any other method?
Maria Laxmi
Ranch Hand

Joined: Aug 08, 2008
Posts: 40
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

Joined: Sep 29, 2008
Posts: 12617

Sure; set up a bunch of threads and have them call it. But that seems like unit-testing the "synchronized" keyword to me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Junit test for synchronized method