File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes repetedly calling a servlet from another servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "repetedly calling a servlet from another servlet" Watch "repetedly calling a servlet from another servlet" New topic
Author

repetedly calling a servlet from another servlet

Alex George
Ranch Hand

Joined: Mar 23, 2007
Posts: 51
My company is in subscription business. Customers come and sign up for products and we send them the product they bought every month.
Sometimes we increase the price. Usually when customers call and complain about the price increase we send them products for the old price (the price they bought the product originally). We do have a jsp form for that. So we fill in the information about the customer in the jsp including their old price and submit to a servlet. The servlet has a method called stickPriceToCustomer(HttpServletRequest request, HttpServletResponse response) which set the old price to the customer. So the customer gets the product for the old price.
Now the company decided to increase the price but the company also decided to sell the product for the old price to all existing customers.
In order to do that what I am planning to do is:
Get the list of all customers from production database and populate a new table in my local database with all the information that need to be submitted to the servlet then write another servlet (just in my local) to get a list of customers and form a url object for each customer and submit the url to the other servlet (in production) to call stickPriceToCustomer(HttpServletRequest request, HttpServletResponse response) method in the servlet.
The idea is that we don’t want to do any release to production at this point and I can do this by writing code in my local (my boss doesn’t want to do any code release to production now).
There are about 20,000 users who subscribed to get the product now.
So my concern is the jsp that I submit to the servlet to invoke the method will take a long time to get the response and eventually will time out (Is that okay. Do I have to be concerned about this?).
And also in my local database I am planning to log all the users that got updated.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30908
    
158

Alex George wrote:So my concern is the jsp that I submit to the servlet to invoke the method will take a long time to get the response and eventually will time out (Is that okay. Do I have to be concerned about this?).

Why? It sounds like you are submitting one request at a time. Each request takes the same amount of time - it's just that there are a lot of them. (You can really do a bunch at a time assuming your code is thread safe. Kick off 10 such programs to hit the server.) This means you won't get a timeout because each request is short. It will take time to make 20K requests, but not as long as you might expect. Especially if you don't wait and do them linearly.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Alex George
Ranch Hand

Joined: Mar 23, 2007
Posts: 51
Thank you for the reply. What I was saying is that even though the new servlet I am planning to write submits one request at a time to the existing servlet, I was thinking of invoking the new servlet to trigger the repeated submission of requests to the existing servlet by submitting a jsp to the new servlet.
So I was concerned that this jsp will wait there and time out.
Do you have any suggestions?
Or may be instead of writing a new servlet, I should write a java class and form a url object and submit to the existing servlet one request at a time.
I also need to log the response into my local database.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18879
    
    8

Sorry, I missed the reason why you're writing a servlet to do this batch task. I don't think you should. Just write a small application which you run from the command line.
Alex George
Ranch Hand

Joined: Mar 23, 2007
Posts: 51
I need to post the request to the existing servlet to set price for each customer. So you think it is better to write a java program that form a url for each user and submit the request for each user. And call this small java program in command line.
Alex George
Ranch Hand

Joined: Mar 23, 2007
Posts: 51
May be you are asking why do I submit one request at a time to the jsp/servlet in production rather than writing a job to do this. Your idea make more sense. But what happened is that somebody did it previously with pearl script from his local machine. So what he did is that he imported the production data to his local database and wrote a pearl script to get the required data from his local database and make repeated calls to the jsp in production to update each customer. He left the company now. So now my boss wants to do the same thing with java because I can check in the code to the version control and if a need arises anybody else can do this.

Any suggestions appreciated.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30908
    
158

Alex George wrote:I need to post the request to the existing servlet to set price for each customer. So you think it is better to write a java program that form a url for each user and submit the request for each user. And call this small java program in command line.

I think you should do that too. I didn't realize you were talking about a servlet at your end.
Alex George
Ranch Hand

Joined: Mar 23, 2007
Posts: 51
I think what you are saying is that instead of writing a servlet at my end, I should write a regular java program and form a url object and submit this to the existing jsp/servlet in production for each user within a loop. This way I can specify some parameters in the method that form the url to pick up customers from 1 to 5000 in one call and 5000 to 10000 in another call and so on and get it done faster.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30908
    
158

Alex George wrote:I think what you are saying is that instead of writing a servlet at my end, I should write a regular java program and form a url object and submit this to the existing jsp/servlet in production for each user within a loop. This way I can specify some parameters in the method that form the url to pick up customers from 1 to 5000 in one call and 5000 to 10000 in another call and so on and get it done faster.

Correct. That also provides for better error recovery. Your application can log the ones that didn't work for later investigation - and it will be easier to retry just those.
Alex George
Ranch Hand

Joined: Mar 23, 2007
Posts: 51
Thank you. Feel so good to hear it from experts.
Alex George
Ranch Hand

Joined: Mar 23, 2007
Posts: 51
A follow up question on this. I ended up writing a java class that does repeated url submissions to the jsp to set the price. My question is if I run this java class with parameters to pick up orders from 1 to 5000, then run the same java class with parameters to pick up orders from 5001 to 10000 and so on, is that thread safe? Essentially I am running the same java class simultaneously with different parameters.
If you guys forgot what this java class does, all this does is to form a url and submit to a jsp to set price for an item for a customer.
jkjllkj jkjllkj
Greenhorn

Joined: Mar 03, 2009
Posts: 3
[ARG: Removed BA post ]
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

"jkjllkj jkjllkj " Welcome to Javaranch
please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.


SCJP, SCWCD.
|Asking Good Questions|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: repetedly calling a servlet from another servlet