nio

Looking up how much direct buffer memory is available to Java?

How can one look up how much direct memory is currently allocated (and may be allocated) by Java? As the evaluator of http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4879883 mentions, Java maintains these buffers outside the normal Java heap. ...

Why FileChannel in Java is not non-blocking?

I wanted to write a program which writes to multiple files simultaneously; thought it will be possible with one thread by using non-blocking mode. But FileChannel does not support non-blocking mode. Does anybody know why? ...

Would FileChannel.read read less bytes than specified if there's enough data?

For example I have a file whose content is: abcdefg then i use the following code to read 'defg'. ByteBuffer bb = ByteBuffer.allocate(4); int read = channel.read(bb, 3); assert(read == 4); Because there's adequate data in the file so can I suppose so? Can I assume that the method returns a number less than limit of the given buffer...

How do I declare a variable that contains a subclass of a class which implements an interface?

I want to declare a variable which holds a class which implements a specific interface. Specifically, I'm trying to store a SocketChannel and a DatagramChannel in the same property so I can use them interchangeably. Both of these classes extend SelectableChannel and also implement ByteChannel, and I wish to call methods from both. I d...

Behavior of the FileChannel to RandomAccessFile

I have one use-case where my multiple threads are writing data to same file channel (pooled), and each thread has offset in the file from where they can start writing till the length of the data to be written. So when I ask the file channel from pool it will open the channel in "rw" mode if it already not opened and will return that file...

Java netty can only take X number of request per second?

Java netty can only take X number of request per second? With the selector approach is it true that it can be a bottleneck in terms of serving request per second? We find that when the traffic is high, clients are unable to connect through, resulting in a time out. ...

closing a socket channel asynchronously

I have a single-threaded non-blocking socket IO server written in Java using nio. When I have finished writing to a connection, I want to close it. Does the closing of the channel mean blocking until all buffered writes have been acknowledged by the recipient? It would be useful to know if, when asynchronously closing, it succeeded or...

Are the ByteBuffer/IntBuffer/ShortBuffer Java classes fast??

I'm working on an Android application (in Java, obviously) and I recently updated my UDP reader code. In both versions, I set up some buffers and receive a UDP packet: byte[] buf = new byte[10000]; short[] soundData = new short[1000]; DatagramPacket packet = new DatagramPacket (buf, buf.length); socket.receive (packet); In the initia...