Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread for calling simultaneously

 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have one of my java Bean where i wrote my logic for updating the data to DB and ......... I need to test this method with 2 simultaneous requests so that i can check for concurrency issues

I need a piece of code which invokes my java bean method twice at the same time ..There should not be any delay in between

Is this possible ??
 
Reghu Ram Thanumalayan
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Initiate the two requests in two separate threads. But the actual execution of the threads and the time slicing are OS dependent.

If you are testing concurrency issues, when the first request updated the db, the second request should be waiting to obtain the lock the first request has acquired. Hope this helps
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you just asking how to start threads? You can make a class that extends Runnable and put some test code in the run() method. Then this will run two copies on two new threads about as close to simultaneously as you can get:

It's notoriously difficult to make threads get into nasty contention in a test ... it usually only happens during demonstrations to your customer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic