Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Is it a good idea to spawn a thread from a servlet?

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have an application which generates reports. Currently this is already in place. Here a servlet (A) invokes another servlet (B) to get the job done. Now i have a new requirement to run multiple reports at a time. I have done it in a sequential manner. Thus A invokes B several times one after another. For the generate of each report a DB2 sp is invoked ( which get the Report data). Actually the DB2 sp is time sonsuming & it take an average of 15 mins. Thus if i have 5 reports to be run it will take an avg of 15 * 5 = 75 mins.
I have 2 queries:
1. If i do this in a multithreaded way ( by spawning different threads for each reports form Servlet A )will it help reducing the time?
2. Is it a good idea to spawn a thread from a servlet?

Regard,
Saj
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multiple reports at a time? Is it for one user or multiple user.
- If multiple user then servlet is already multithreaded.
- If one user, then why need multiple reports simultaneously?

I think you need to tune your SQL or DB.
- Indexes must be there on appropriate columns. Specifically on columns which participates in condition
- ORing should be after ANDing
- Use LIKE operator instead of functions like substr(), if any is being used.
 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is for One User. Multiple reports run simultaneously for 1 user. For each report a .csv file is generated
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would avoid it if possible.
Threads started from within web apps can have adverse effects when trying to reload the application and/or restart the server.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds like a candidate for an asynchrous process - since the DB operation is so time consuming, you can't reasonably expect the user to wait for a response. Perhaps JMS to generate the reports and JavaMail to delover them?

I have to agree with Adeel Ansari though, if this is taking so long you might want to review your DB configuration and/or how you've written your Stored Precedures.
[ March 29, 2005: Message edited by: Paul Sturrock ]
 
You got style baby! More than this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic