 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Alan Shiers Guest
|
Posted: Sat Apr 02, 2005 6:21 pm Post subject: OutOfMemory Error |
|
|
Hi there,
I am working on a project that involves an applet containing a JList which
is supposed to load with records obtained from sending a request to a
servlet which, in turn, queries a database. The requested records are then
encapsulated into a serialized object (named TableData) as a 2D array and
sent to the applet. All of this works great except when the number of
records returned start to exceed 15. This is when the applet generates an
OutOfMemory Error. This isn't good!
In the Java Console I increased the Java Runtime Parameters property
to -Xmx128m. This didn't help. I tried -Xmx256m and that didn't help. Mind
you, I only have 327 megs of RAM on my system anyway with 6 or more windows
open. Maybe that has something to do with it? When loading up large amounts
of data into an applet like this, is there a more efficient way to do it so
as to prevent OutOfMemory errors?
Alan
|
|
| Back to top |
|
 |
Lori M Olson [TeamB] Guest
|
Posted: Sat Apr 02, 2005 8:28 pm Post subject: Re: OutOfMemory Error |
|
|
Alan Shiers wrote:
| Quote: | Hi there,
I am working on a project that involves an applet containing a JList which
is supposed to load with records obtained from sending a request to a
servlet which, in turn, queries a database. The requested records are then
encapsulated into a serialized object (named TableData) as a 2D array and
sent to the applet. All of this works great except when the number of
records returned start to exceed 15. This is when the applet generates an
OutOfMemory Error. This isn't good!
In the Java Console I increased the Java Runtime Parameters property
to -Xmx128m. This didn't help. I tried -Xmx256m and that didn't help. Mind
you, I only have 327 megs of RAM on my system anyway with 6 or more windows
open. Maybe that has something to do with it? When loading up large amounts
of data into an applet like this, is there a more efficient way to do it so
as to prevent OutOfMemory errors?
Alan
|
I think you need to profile that applet. Unless those records contain
huge CLOBs or BLOBs, I can't see why you'd need that much memory. There
must be something else amiss.
Keep in mind that you can only display so much data at a time in the
applet. There are many different strategies for dealing with large data
sets. One is built in to the JDK in the form of scrollable ResultSets
http://java.sun.com/docs/books/tutorial/jdbc/jdbc2dot0/cursor.html
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
http://www.visi.com/~gyles19/fom-serve/cache/1.html
|
|
| Back to top |
|
 |
Alan Shiers Guest
|
Posted: Sun Apr 03, 2005 4:27 pm Post subject: Re: OutOfMemory Error |
|
|
Hi Lori,
"Lori M Olson [TeamB]" <javadragon (AT) techie (DOT) com> wrote
| Quote: |
I think you need to profile that applet. Unless those records contain
huge CLOBs or BLOBs, I can't see why you'd need that much memory. There
must be something else amiss.
|
I'm afraid I don't understand what you mean by "profile" the applet. What
is that?
I had a quick peek at the start of tutorial you mention, but I don't think
it will help me much since the applet communicates with a Servlet, and the
database query is made on the server-side by the Servlet. The query returns
a resultSet which I then convert to a 2D array of data and send it back to
the applet via a serialized class named TableData. No matter how much data
there is, I need to get that data to the applet either all at once or a bit
at a time. The tutorial, I think, pertains to standalone applications, not
network programming?
If you want, I can show you the applet and servlet code that I've been
using, if you think that would help you to understand what I've been doing
this far?
Alan
|
|
| Back to top |
|
 |
Lori M Olson [TeamB] Guest
|
|
| Back to top |
|
 |
Paul Nichols (TeamB) Guest
|
Posted: Mon Apr 04, 2005 7:39 pm Post subject: Re: OutOfMemory Error |
|
|
"Alan Shiers" <ashiers (AT) hfx (DOT) eastlink.ca> wrote
| Quote: | Hi Lori,
"Lori M Olson [TeamB]" <javadragon (AT) techie (DOT) com> wrote in message
news:424f0065$1 (AT) newsgroups (DOT) borland.com...
I think you need to profile that applet. Unless those records contain
huge CLOBs or BLOBs, I can't see why you'd need that much memory. There
must be something else amiss.
I'm afraid I don't understand what you mean by "profile" the applet. What
is that?
Lori is suggesting that you use a memory profiler to check memory usage on |
your applet. If you are running out of memory, more than likely, you have a
memory leak, or you are attempting to create a new object of some type and
you are not freeing it (ie native call, static method/class that is
instantiated several times and is never released, or a Database,
ProcedureDataSet, ResultSet, etc. that is not released).
|
|
| Back to top |
|
 |
Alan Shiers Guest
|
Posted: Tue Apr 05, 2005 5:11 pm Post subject: Re: OutOfMemory Error |
|
|
"Paul Nichols (TeamB)" <paul (AT) computer-logic (DOT) net> wrote
| Quote: |
"Alan Shiers" <ashiers (AT) hfx (DOT) eastlink.ca> wrote in message
news:42501b60$1 (AT) newsgroups (DOT) borland.com...
Hi Lori,
"Lori M Olson [TeamB]" <javadragon (AT) techie (DOT) com> wrote in message
news:424f0065$1 (AT) newsgroups (DOT) borland.com...
I think you need to profile that applet. Unless those records contain
huge CLOBs or BLOBs, I can't see why you'd need that much memory.
There
must be something else amiss.
I'm afraid I don't understand what you mean by "profile" the applet.
What
is that?
Lori is suggesting that you use a memory profiler to check memory usage on
your applet. If you are running out of memory, more than likely, you have
a
memory leak, or you are attempting to create a new object of some type and
you are not freeing it (ie native call, static method/class that is
instantiated several times and is never released, or a Database,
ProcedureDataSet, ResultSet, etc. that is not released).
|
I don't have a profiler, and if I did I wouldn't know how to use it. I
downloaded JProbe but its going to take me some time to figure out how to
use it. I did check for items in your list. I don't do any native call.
There are no static methods or classes that are being instantiated. The
database is on the server side and therefore doesn't affect the applet.
I did try another approach to solve my problem, which appears to work. As
previously mentioned, I am using a serialized class name TableData which
wraps a 2D array. I send TableData over the wire in either direction to
move the data. When I used writeObject() to send an instance of TableData
out of the applet to the server, and TableData would have a fully loaded 2D
array with many records. This didn't seem to be a problem for the applet,
and the Servlet at the other end accepted TableData without flinching. It
was only when I tried sending data in the reverse direction, in the same
manner, that the applet would scream OutOf Memory error on the readObject()
method. The only thing I could conclude from that was, a single TableData
object with many records was too much for the applet to handle all at once
with its memory restrictions. So, my next idea was to set up a looping
structure at both ends and send each record from the database one at a time,
encapsulated in TableData objects. The resulting method was created for the
applet:
private String[][] getAllRecords(String requestType)throws
NoParameterException, MalformedURLException, IOException,
ClassNotFoundException
{
if(originalListDataServlet.equals(""))
throw new NoParameterException("originalListDataServlet");
String[][] temp = null;
try
{
URL testServlet = new URL( originalListDataServlet );
URLConnection servletConnection = testServlet.openConnection();
if (servletConnection instanceof HttpURLConnection)
{
((HttpURLConnection)servletConnection).setRequestMethod("POST");
}
else
{
System.out.println("this connection is NOT an HttpUrlConnection
connection");
temp = new String[0][0];
return temp;
}
//inform the connection that we will send output and accept input
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
//Don't use a cached version of URL connection.
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches (false);
//Specify the content type that we will send binary data
servletConnection.setRequestProperty ("Content-Type",
"application/octet-stream");
//send your request to the servlet
ObjectOutputStream outputToServlet = new ObjectOutputStream(new
BufferedOutputStream(servletConnection.getOutputStream()));
TableData request = new TableData();
request.setRequestType(requestType);
request.setCompanyID(companyID);
request.setAdminID(administratorID);
outputToServlet.writeObject(request);
outputToServlet.flush();
//now wait for a response from the servlet
ObjectInputStream response = new ObjectInputStream(new
BufferedInputStream(servletConnection.getInputStream()));
// Read response back from the server
// A series of TableData objects will arrive from the server
// and each will contain one record from the database.
//NOTE: THIS APPROACH IS NECESSARY BECAUSE IF I LOAD A SINGLE
//TABLEDATA OBJECT WITH ALL THE RECORDS AT ONCE, I GET AN OUTOFMEMORY
ERROR
//FROM THE APPLET.
// This first Object returned will simply indicate
// the number of records being returned.
Object count = response.readObject();
if(count instanceof String)
{
int NumberOfRecords = Integer.parseInt((String)count);
Object record = null;
TableData td = null;
String[][] RecordData = null;
//System.out.println("Number of Records: " + NumberOfRecords);
for(int i = 0; i < NumberOfRecords; i++)
{
record = response.readObject();
if(record instanceof TableData)
{
td = (TableData)record;
RecordData = td.getData();
if(i == 0)
{
//Dimension temp
temp = new String[NumberOfRecords][RecordData[0].length];
}
for(int j = 0; j < RecordData[0].length; j++)
{
temp[i][j] = RecordData[0][j];
/*
if(j != 2)
System.out.print(RecordData[0][j] + " ");
else
System.out.println(RecordData[0][j]);
*/
}
}
}
record = null;
td = null;
RecordData = null;
//Lastly, close the streams
outputToServlet.close();
response.close();
outputToServlet = null;
response = null;
System.gc();
}
}
catch(NumberFormatException nfe)
{
throw nfe;
}
catch(MalformedURLException mue)
{
throw mue;
}
catch(IOException ioe)
{
throw ioe;
}
catch(ClassNotFoundException cnfe)
{
throw cnfe;
}
return temp;
}
Now that I got this working, I'm thinking I can make it even better if I
encorporate using xml files to move the data back and forth instead of a
serialized object. What do you think? Do applets and reading/writing xml
work well together?
Alan
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|