aspose file tools*
The moose likes Testing and the fly likes Is it possible to start 20 Threads Simultaneosly under a JUnit TestCase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Is it possible to start 20 Threads Simultaneosly under a JUnit TestCase " Watch "Is it possible to start 20 Threads Simultaneosly under a JUnit TestCase " New topic
Author

Is it possible to start 20 Threads Simultaneosly under a JUnit TestCase

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi ,

I have written a StatelessSession Bean , that actually does some insert operation into Database based upon the data passed to it .
This works fine when tested as a Single User .

Now i want to test this under Production Environment where Multiple users can get access to this Bean and perform a insert Operation from the User Interface .

So is it possible to write a JUnit TestCase in such as Way that i can start 20 Threads at a time and test this functionality ??

please help .

Thanks in advance


Save India From Corruption - Anna Hazare.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

A JUnit test can do anything it wants, including starting up threads.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thanks David , i can do that but the concern is how can i make sure that the Threads are started at the same time and making the calls Simultaneously ?? Any ideas thanks in advance .

Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1760
    
    7

You can make use of java.util.concurrent.CyclicBarrier to maximize concurrency in your test case.
Simply fire up an arbitrary number of threads that wait at a CyclicBarrier, which will release them once that number is reached.
Also make sure that once a thread has finished its task, it waits at another CyclicBarrier.
That way further test logic (assertions for instance) will only run after every thread has finished.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it possible to start 20 Threads Simultaneosly under a JUnit TestCase