File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Thread for calling simultaneously Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Thread for calling simultaneously" Watch "Thread for calling simultaneously" New topic

Thread for calling simultaneously

sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415

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

Joined: Oct 21, 2003
Posts: 193
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

Cheers,<br />Reghu Ram T<br /> <br />SCJP 1.4 - 98 %, SCBCD 1.3 - 94 %, SCMAD 1.0 - 92 %
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Thread for calling simultaneously
It's not a secret anymore!