• Post Reply Bookmark Topic Watch Topic
  • New Topic

Out of memory due to vectors

 
Nitin Kalra
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have developed a website which has a heavy rolling of data.

I have made some generic classes for the interaction of data in it. This generic class runs the given query and whatever data obtained in the resultset, is been inserted into a vector at the desired index likeways asked in the query to be fetched.
This all is working very much fine on Windows. But as i launched this application on solaris There were a few queries which had heavy data retrieval made the server crash(hang).
When i ran the performance tuning tools i came to know that the vectors are generating enormous objects which cannot be handled by the server.
My problem lies here. I have a solution for it to return the resultset as it is and not the vector. But this will include a lot of changes in the application, since the whole logic has already been written as like for the vector.

Please can you suggest me a way out with minimum changes and not hindering the architecture of the application the way it is right now!
 
Wendal Park
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, you may try to initialize a bigger heap size for your JVM in the Solaris machine.
The second step would be to optimize your query so as to return just the right amount of information (i.e. fields) in the resultSet you need from the database.
But to cure the real problem, I think adding resultSets directly into Vector is not an optimal solution. For most of the time, I think you only need those columns returned in the resultSet for data processing. So why not creating a DAO (Data Access Object) which offers mutators and accessors (i.e. Get/Set methods) that maps the columns of the resultSet. Then put these DAOs into the Vector. In this case, you can control the number of fields that you really need.
My last note would be to use Vector's interface, List, to be the data structure holding all these objects. I *think* List has fewer APIs than Vector, and should have smaller size in memory than Vector objects. Then at the end, you can always cast the List back into Vector to handle the internal elements.
 
Nitin Kalra
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i have not created DAO, but i am extracting data from the resultset and keeping the data in the Vector as its elements, thats results in heavy creation of objects and memory allocation, i am looking for the way by which i can get rid of these object creation process, with lesser changes in my code.
Thanks in Advance.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nitin Kalra:
My problem lies here. I have a solution for it to return the resultset as it is and not the vector. But this will include a lot of changes in the application, since the whole logic has already been written as like for the vector.

Please can you suggest me a way out with minimum changes and not hindering the architecture of the application the way it is right now!

No, sorry.
As you said, if the whole application expects a Vector, there simply is no easy way to *not* use Vector any longer.
The same would be true if you changed it to use ResultSet - once you decided that using ResultSet wasn't the best idea, you had to change the whole application again!
So what you should do is encapsulate the use of Vector/ResultSet/whatever in one single place, therefore decoupling the rest of the application from this design decision. That will probably be a lot of work know that the coupling to Vector already exists, but will give you much more flexibility in the future.
With other words, it isn't the current architecture that you should want to preserve, as it is this rigid architecture which is causing your trouble!
[ January 24, 2003: Message edited by: Ilja Preuss ]
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:
As you said, if the whole application expects a Vector, there simply is no easy way to *not* use Vector any longer.
There isn't, but... you might perhaps be able to write a wrapper class which turns a scrollable ResultSet into a List (or even a Vector). It won't be pretty, and you will probably find that there are a couple of places where performance has gone down the drain, but it might save you some work.
You would still have to add a mechanism to ensure that the ResultSet would be closed and their underlying connections returned to the pool though -- you probably won't want to wait for finalization.
- Peter
[ January 24, 2003: Message edited by: Peter den Haan ]
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you checked the capacityIncrement of your vector. The size of the vector's storage doubles whenever the capacity is exceeded if the capacityIncrement is less than or equal to zero. you could probably set the capacityIncrement at greater than zero.
hope this helps somehow.
[ January 24, 2003: Message edited by: boyet silverio ]
 
Nitin Kalra
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Thanks for the response. about if i write a wrapper class for the vector itself anddo my work with arrays. Will it solve the memory problem of creation of more objects?
Thanks
- Nitin
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nitin Kalra:
Thanks for the response. about if i write a wrapper class for the vector itself anddo my work with arrays. Will it solve the memory problem of creation of more objects?

Vector already works on arrays internally - it is just able to extend its size by instanciating a new, bigger array and copy the content of the old one into the new one.
So, if you instanciate the Vector with the "correct" initial size, it already should work that way.
 
Nitin Kalra
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
That is very much true that vector works internally on arrays....but those are object array which is causing the memory overflow in the application. What i was mentioning was of String Arrays.
I hope String arrays will be created as a single object and when we put more values the size of the object is increased and not the number of objects which happens in the case of vectors.
Is this solution has any disadvantages or if there is some other solution which comes in your minds then please suggest me.
Thanks
- Nitin
[ January 26, 2003: Message edited by: Nitin Kalra ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nitin Kalra:
Hi,
That is very much true that vector works internally on arrays....but those are object array which is causing the memory overflow in the application. What i was mentioning was of String Arrays.
I hope String arrays will be created as a single object and when we put more values the size of the object is increased and not the number of objects which happens in the case of vectors.

I don't understand. Why exactly do you think a String array would make a difference???
 
Nitin Kalra
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it is majorly because when we insert anything new in any vector then it is treated as a new object while in the case of string array if we insert anynthing new in the Strring array then finally the result obtained will be only one object....it is just that the size of the obtained object will increase and not result in increasing of the number of objects which happens to be in the case of vectors which results in creation of new object.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't get it from your description - perhaps some example code would help?
 
Dhananjay Inamdar
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Nitin,
My suggestion is to go for the ArrayList insted of the vector in you existing application. Arraylist works much more in the same way that of Vector, so there will be major change required in your current aplication. Advantage of Arraylist is that vector is heavily synchronized and ArrayLists are not.
For the problem of resultset, if you are getting the big resultset then my suggestion is to use the cached rowset insted of storing it in lcal vecots or arraylists. Rowsets works in the offline to the resultset. Resultset always required he open connection.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!