Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About String usage

 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

I was working on a application which gets a XML file as input which i am going to parse using SAX parser. In my code i have defined lot of variables (around 60 to 70 String objects) in the fashion shown below



as you can see all these objects are final which i am going to use it for String equality check condition. I am getting worried about the amount of memory these String objects consume. Is there a better way of doing the same thing?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am getting worried about the amount of memory these String objects consume.

Why? Are you seeing performance issues with your applications? Do you have a very constrained deployment environment?


Is there a better way of doing the same thing?

I'm guessing these variables match the elements you need to parse? If this is the case, no. You need the have the element name in order to match it.
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why? Are you seeing performance issues with your applications? Do you have a very constrained deployment environment?


Yes, it takes some time to finish parsing the XML file.
To be more clear i am generating my application GUI based on the XML file and after parsing through the file then only i am able to get the GUI which requires some time.


I'm guessing these variables match the elements you need to parse? If this is the case, no. You need the have the element name in order to match it.


Yes i am using those variables for that purpose while parsing.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parsing XML files can be slow. Its unlikely it is your use of these String variables that is the cause is though. It is also unlikely that memory is the constraint. If it were, you might start to see OutOfMemoryErrors. My guess is the bottleneck is the CPU.

There is a general rule for Swing applications, do not do lengthy non-GUI work on the event-dispatch thread. Do you need to use or show your entire XML model when you start your application, or can you use SwingUtilities to improve the responsiveness of the GUI?
 
Mintoo kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's better use SAX parser API ,where every method which is required to parse XML file has given. That will be helpful.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mintoo kumar:
It's better use SAX parser API ,where every method which is required to parse XML file has given. That will be helpful.


Balasubramanian Chandrasekaran is using a SAX parser.
 
Mintoo kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my focus was like

origina post code:
--------------------------------------------------------------------------------

public static final String STARTING_TAG = "start";public static final String ELEMENT_START_TAG = "element";...............public static final String ENDING_TAG = "end";

--------------------------------------------------------------------------------

rather using these elements use the methods and all the facility avliable in SAX parser API.

Hope i made the point correctly.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure I follow. My assumption is Balasubramanian Chandrasekaran is using these values to work out what to do with an element when the Handler's startElement method is fired. What SAX API methods do you mean?
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul you are correct, I use those String object for equality check.

My scenario is:
1. I will check whether i got my application starting tag by checking the parsed value to my STARTING_TAG object if that matches i will be doing relevant operations like constructing a new JFrame which will get all the components.
2. Then i will again check the equality condition on parsed value with my ELEMENT_START_TAG and then i will check what is that type of element and construct the relevant component onto the JFrame which i created previously.

....... Likewise it goes.

And can you please explain in detail.What you mean by

Do you need to use or show your entire XML model when you start your application, or can you use SwingUtilities to improve the responsiveness of the GUI?


Regarding Mintoo Kumar reply,

rather using these elements use the methods and all the facility avliable in SAX parser API.

I don't get what you are trying to convey?


After Displaying my JFrame i am calling


Whether this will guarantee Garbage Collection on my String objects??
[ May 13, 2008: Message edited by: Balasubramanian Chandrasekaran ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic