[xSocket-develop] suspendRead() and resumeRead() cause program hang?
Status: Inactive
Brought to you by:
grro
|
From: fulichen <ful...@du...> - 2008-04-22 01:57:01
|
Hello Gregor,
Thanks for your response, but we find suspendRead() and resumeRead() will cause program hang, is it a bug (maybe there is race condition)? or how can we fix our test?
The test program is following, and the test environment Java version 1.6.0_03 on Windows Vista.
TestClient result hanging a while after start (but not each TestClient test, try some times will get hang)
=================================
public class TestClient implements IDataHandler
{
//-------------------------------
static public void main(String[] args)throws IOException, InterruptedException
{
TestClient c = new TestClient();
NonBlockingConnection nbc = new NonBlockingConnection("127.0.0.1", 1000, c);
Thread.sleep(100000000);
}
public boolean onData(INonBlockingConnection connection)throws IOException
{
System.out.println("onData enter");
try
{
connection.suspendRead(); // here call to suspendRead
int available = connection.available();
System.out.println("onData available = " + available);
byte[] data = connection.readBytesByLength(available);
}
finally
{
connection.resumeRead(); // call resumeRead here
System.out.println("onData exit");
}
return true;
}
}
=================================
public class TestServer
{
//-------------------------------
static public void main(String[] args)throws IOException
{
TestServer s = new TestServer();
s.doServer();
}
void doServer() throws IOException
{
ServerSocket ssck = new ServerSocket(1000);
Socket sck = ssck.accept();
OutputStream out = new BufferedOutputStream(sck.getOutputStream());
for (int i = 0; i < 100000000; i++)
{
String s = "Message " + i + "\r\n";
//1.write out a string
out.write(s.getBytes());
//2.write out bytes length
ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.putInt(i);
buffer.rewind();
out.write(buffer.getInt());
//3.write out bytes
byte[] data = new byte[i];
out.write(data);
out.flush();
}
}
}
========================================
TestClient result
onData enter
onData available = 10027
onData exit
onData enter
onData available = 16
onData exit
onData enter
onData available = 3752
onData exit
onData enter
onData available = 10044
onData exit
onData enter
onData available = 3752
onData exit
----- Original Message -----
From: <gre...@we...>
To: "fulichen" <ful...@du...>
Sent: Monday, April 21, 2008 7:21 PM
Subject: Re: [xSocket-develop] OutOfMemory exception
Hi fchen,
by calling the <connection>.suspendRead() you can stop reading the socket. Reading will be resumed by calling the <connection>.reaumeRead() method. For an example see http://xsocket.svn.sourceforge.net/viewvc/xsocket/xsocket/core/trunk/src/test/java/org/xsocket/connection/LimitedReadTest.java?view=markup
Gregor
> -----Ursprgliche Nachricht-----
> Von: "fulichen" <ful...@du...>
> Gesendet: 21.04.08 12:35:09
> An: <xso...@li...>
> Betreff: [xSocket-develop] OutOfMemory exception
Our application need to handle many many connection,
> and the data need time to process,
> because xSocket Dispatcher read data when it is avialable,
> our application often run out of memory.
>
> How we limit Dispatcher data reading, or what can we do to prevent
> OutOfMemoryException?
>
> fchen-----------------------------------------------------------------
> -------- This SF.net email is sponsored by the 2008 JavaOne(SM)
> Conference Don't miss this year's exciting event. There's still time
> to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/
> clk;198757673;13503038;p?http://java.sun.com/javaone__________________
> _____________________________ xSocket-develop mailing list xSocket-
> de...@li... https://lists.sourceforge.net/lists/
>
> listinfo/xsocket-develop
--
Gregor Roth
|