• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trying to speed up some calculations

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a loop for 1 upto 10 cars, inside the loop I call a SpecialOffersCalc class which sets the price, tax, mainteance cost etc for each car
and displays them in the JSP.
This for about 10 cars takes around 10 seconds to do the calculations. I thought in order to improve the speed of this page, I could have a loop and start a thread for each calc so that calcs can be done simultaneously.
Now the calculations in SpecialOffersCalc which is implementing Runnable are done inside public void run() {} - The page executes in a second but all resuls are null. I am useing an instance of SpecialOffersCalc and getter methods to retrieve the values.
Any help in the right direction will be most appreciated.
- FK
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're running the calculations in separate threads, then the main thread really needs to wait for those separate threads before continuing (if this weren't a JSP, there's be other options available, but in this case, you can't return a page until the calculations are done.) You're seeing "null" presumably because you're returning the page before the threads you've started have done their work.
This is a complicated subject, and I could show you an example or two, but you really should learn the fundamentals. I strongly recommend Doug Lea's book Concurrent Programming in Java.
Now, another thing you might consider is how to speed up the calculations. 1 second per car seems awfully slow -- are you hitting a database for each one?
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the direction. I guess I will for now leave it, get my certification out of the way and then study this topic in more detail.
There are a lot of different values being pulled out of different tables, hence the speed.
I guess I'll just store the results in a database table as they will change infrequently.
- FK
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest Friedman-Hill

Originally posted by Ernest Friedman-Hill:

Now, another thing you might consider is how to speed up the calculations. 1 second per car seems awfully slow -- are you hitting a database for each one?


Can you suggest few ways through which we can speed up the calculations, without actually changing the formula. What if we are using a database to access the value. I am asking this question just out of curiosity.
[ July 25, 2003: Message edited by: Anupam Sinha ]
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't suggest ways to speed up the calculations without knowing what they're like. You could show us code or explain more what you have to do for each car.
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest
Thanks for looking into my question. I am actually not the author of this thread and don't about the application. I wanted to know if there are any steps that can or may decrease the time for each computation or access time for database access.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is still the same, I think. No - not without knowing more about the specific application.
Typically, in the Performance forum we discourage people from putting much effort into optimizing before they've tested their code to see how fast it is currently, and whether performance is really even a problem. In this case, we don't even have requirements, much less a coded solution to those requirements. I don't think there's much more that can be said here.
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to say what I did to make the user experience better.
We have an admin screen where the admin guys sets the new vehicles for each corporate that we have. What I have done is rather than generating all the quotes real time (which does not really add any extra value), I have added a button in the admin screen where the admin guy after adding the vehicles can click to save the new quotes in the database.
The user page is now simply pulling out pre-calculated quotes from the database, which obviouslt is very quick.
I think I need to evaluate the underlying quoting mechanism of my application anyway. There are about 20 different queries at the moment that form part of a quotation, partly due to the way the tables were designed in the past.
 
reply
    Bookmark Topic Watch Topic
  • New Topic