Forums Register Login

Trying to speed up some calculations

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1051 times.
Similar Threads
Question about using Multi-threading
Running a quote in threads.
Performance difference between different ways of iteration
session
Reading a CSV file--> Fastest way
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:04:36.