directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Johannes Zillmann <jz8_b...@yahoo.de>
Subject Re: [MINA] OutOfMemoryError on streaming large files
Date Mon, 12 Dec 2005 16:52:01 GMT
Thank you for response !

--- Niklas Therning <niklas@trillian.se> schrieb:
> Are you running both the client and server in the
> same VM? If you are, 
> please try to run them in separate VM:s and see if
> both still run out of 
> memory. 

Yes both are in one vm. I can try with seperation but
later.

> I suspect that some buffer isn't released
> properly but it seems 
> unlikely that both ends fail at the same time unless
> they are in the 
> same VM.
> 
> The maximum heap size is at 64 MB, right?

 right !

> Would it possible for you to post your code (the
> relevant parts) to the 
> list?

I will try it with some semi code lines in it...
the sending part(inside a filer):

public void filterWrite(NextFilter nextFilter,
IoSession session, WriteRequest writeRequest) throws
Exception {
 if (message instanceof InputStream) {
while (inputStream.available() > 0) {
            ByteBuffer buffer =
ByteBuffer.allocate(4*1024);
            FileUtil.writeBytes(inputStream,
buffer.asOutputStream(), 4*1024);
            buffer.flip();
            
            nextFilter.filterWrite(session, new
WriteRequest(buffer, writeRequest.getFuture()));
            if(10MB are written)
                Thread.sleep(500);
            //other wise the memory exception will
raise earlier (but increasing sleep has no effect even
if its 5000)
        }
        inputStream.close();
 }
}

the receiving part(inside a filer):

//get the IoSessionInputStream
InputStream inputStream = session.get(KEY_IN);
        File copy = new File("target/testFileCopy");
        outputStream = new FileOutputStream(copy);
        FileUtil.writeBytes(inputStream,
outputStream);

whereby the FileUtil methods looks like:

 public static void writeBytes(InputStream iStream,
OutputStream oStream, int length) throws IOException {
        byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];
        int pieceLength = bytes.length;
        while (length > 0) {
            if (length < bytes.length)
                pieceLength = iStream.read(bytes, 0,
length);
            else
                pieceLength = iStream.read(bytes, 0,
bytes.length);

            if (pieceLength == -1) {
                return;
            }
            
            oStream.write(bytes, 0, pieceLength);
            length -= pieceLength;
        }
    }

and:

 public static void writeBytes(InputStream iStream,
OutputStream oStream) throws IOException {
        int length = -1;
        byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];
        while ((length = iStream.read(bytes)) != -1) {
            oStream.write(bytes, 0, length);
        }
    }

hope this is readable and helps!
best regards 
johannes



	

	
		
___________________________________________________________ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de

Mime
View raw message