• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JUnit test can do anything it wants, including starting up threads.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!