C
Camille
Hi,
first of all, i'm not sure of the newsgroup to post this message.
If i'm not in the good place, please tell me.
I'm using NIO in a client server project, and from a sudden, I get
OutOfMemoryException.
After some search on the web, I found that ByteBuffer.allocateDirect
was often a problem if the heap size was too low.
BUT, the problem is that I get this exception when writing on NIO, not
when reading.
Here's the code :
FIFOQueue m_responsesQueue = new FIFOQueue();
....
AKSResponse response = null;
SocketChannel client;
Charset charset = Charset.forName("UTF-8"); // client encoding
while (m_responsesQueue.size() > 0)
{
response = (AKSResponse) m_responsesQueue.getFirst();
client = response.getChannel();
if (client.isOpen())
{
if (!client.socket().isClosed())
{
if (!client.socket().isOutputShutdown())
{
client.write(charset.encode(response.getData()));
}
}
}
response.free();
response = null;
m_responsesQueue.dequeue();
}
And I get the following :
java.lang.OutOfMemoryError
at sun.misc.Unsafe.allocateMemory(Native Method)
at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:99)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:285)
at sun.nio.ch.Util.getTemporaryDirectBuffer(Util.java:54)
at sun.nio.ch.IOUtil.write(IOUtil.java:69)
at
sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:300)
at aks.gameServer.net.AKSWriteDaemon.run
(AKSWriteDaemon.java:102)
The line 102 being the client.write(charset.......
I presume I have to allocate more memory to my VM with the Xmx, Xmn,
X... settings, but I'm confused with all the possibilites : what about
XNewSize, XMaxNewSize, Xms, ...
Thanks in advance for your help,
Camille
--
first of all, i'm not sure of the newsgroup to post this message.
If i'm not in the good place, please tell me.
I'm using NIO in a client server project, and from a sudden, I get
OutOfMemoryException.
After some search on the web, I found that ByteBuffer.allocateDirect
was often a problem if the heap size was too low.
BUT, the problem is that I get this exception when writing on NIO, not
when reading.
Here's the code :
FIFOQueue m_responsesQueue = new FIFOQueue();
....
AKSResponse response = null;
SocketChannel client;
Charset charset = Charset.forName("UTF-8"); // client encoding
while (m_responsesQueue.size() > 0)
{
response = (AKSResponse) m_responsesQueue.getFirst();
client = response.getChannel();
if (client.isOpen())
{
if (!client.socket().isClosed())
{
if (!client.socket().isOutputShutdown())
{
client.write(charset.encode(response.getData()));
}
}
}
response.free();
response = null;
m_responsesQueue.dequeue();
}
And I get the following :
java.lang.OutOfMemoryError
at sun.misc.Unsafe.allocateMemory(Native Method)
at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:99)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:285)
at sun.nio.ch.Util.getTemporaryDirectBuffer(Util.java:54)
at sun.nio.ch.IOUtil.write(IOUtil.java:69)
at
sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:300)
at aks.gameServer.net.AKSWriteDaemon.run
(AKSWriteDaemon.java:102)
The line 102 being the client.write(charset.......
I presume I have to allocate more memory to my VM with the Xmx, Xmn,
X... settings, but I'm confused with all the possibilites : what about
XNewSize, XMaxNewSize, Xms, ...
Thanks in advance for your help,
Camille
--