• 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

Help on improving Performance

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have three doubts in perofrmance fix

1. Is better to use Switch case (using enums for string) or if else .. if the options are exceeding 50.
2. There is a POJO class. am calling obj.getxxx() method several times in other class instead of creating a variable for it.
Is it a better practice or creating a variable and using it is better?
3. This is regarding JDBC and JSP using Oracle10g,Tomcat and JBOSS.Currently this is the scenario. I am retreiving more than 1000 records in resultset. But actually the user requires 10 records..rarely he requires 1000 records. Am iterating thru a loop in DAO class and getting that particular records in while(resultset,next()) and passing them to JSP (thru request obect)
If the user again requests for 20 records..am again doing the same.
Because of this the query is executing again and again. and the server is becoming very slow.
(The code written long back and also not upto the standards and performance is not considered while developing)
But Now, i want to change it like..
1.Keepiing the resultset in a map and want to store in sessionObject. whenever the user again wants 10,20, 30 or all the records , i wil get them from session and wants to display in jsp.
2.Using rowid concept in query itself while retreiving the records.
Which one is better? or is there any otherways of doing it

Please help and correct me..



 
Author and all-around good cowpoke
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. I go with switch/case for all but the simplest branching but mainly for clarity and because I tend to think in terms of state machines.
2. Best practice is to use whatever is clearest - personally I use public variables unless the JavaBeans API is involved
3. I have no idea because I don't do JDBC but I bet you can get suggestions here.....

Bill
 
g venkata
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

2. Best practice is to use whatever is clearest - personally I use public variables unless the JavaBeans API is involved



Thank you bill for your suggestions..
But, i am using bean type setter and getter methods. like JavaBeans API
Shall I create a String variable for it.. and use it whereever requried?.
If so, I need to create 20 string variables like that.
or shall I call getter methods for all of them.
which would be better?

Please suggest
 
Sheriff
Posts: 7135
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:2. Best practice is to use whatever is clearest - personally I use public variables unless the JavaBeans API is involved


Couldn't this be a problem whenever you need to add some validation or other stuffs in future development? If setters and getters are used, such integration could be done without modifying the other components...
I agree that public exposure is suitable for final static variables, though.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what I have done when it is necessary to recognize Strings and switch accordingly.

Create a static String[] of all the Strings you need to recognize.
Create a static int[] matching the strings with integer values you will use in a big switch/case construct.
On creation of a class instance, build a Hashmap with the Strings as keys and the matching int values as Integer values.

At the point where you need to select code based on the value of a String, use it to look up the matching Integer and use that value in the switch.

Advantages: multiple words can be mapped to the same Integer, adding a new word/state is easy and does not change the rest of the code.

Bill
 
Greenhorn
Posts: 5
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

g venkata wrote:I have three doubts in perofrmance fix
3. This is regarding JDBC and JSP using Oracle10g,Tomcat and JBOSS.Currently this is the scenario. I am retreiving more than 1000 records in resultset. But actually the user requires 10 records..rarely he requires 1000 records. Am iterating thru a loop in DAO class and getting that particular records in while(resultset,next()) and passing them to JSP (thru request obect)
If the user again requests for 20 records..am again doing the same.
Because of this the query is executing again and again. and the server is becoming very slow.
(The code written long back and also not upto the standards and performance is not considered while developing)
But Now, i want to change it like..



for this thing, i have suggestion for you, get the records only in the exact what user needs, if they are needing 100 records, so only get the 100 records in the database level, you can use LIMIT for mysql, Rownum for ORACLE and so on.

If you only need 100 records, why would you fetch 1000 records ? the rest 900 will be useless and big enemy in performance.

 
Greenhorn
Posts: 23
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Choosing on how much records to be fetched depends on the scenario.

1. If you need the records too frequently, you should not query the database again and again as connection to it and querying takes a lot of time, but keep it in memory(collection or some data structure) and return by iteration to the JSP. have more efficient query to the database.

2. If you don't need the records too frequently, you can query the database for exactly what you need even if it is done little frequently.
 
reply
    Bookmark Topic Watch Topic
  • New Topic