Re: Switching from Non-Blocking to Blocking IO



Mike Schilling schrieb:
Christian wrote:
Hello


I have just tried using non-Blocking IO in a JavaSE program.
My problem is that at one point I have to switch during the the
running protocol to blocking-io as some compressed data arrives and
my gzip implementation only allows decompressing from a blocking
stream.


so what I tried was this

@Override
public ByteChannel retrieveChannel() throws IOException {

SocketChannel sc = (SocketChannel)key.channel();
key.cancel();

sc.configureBlocking(true);
sc.socket().setSoTimeout(20000);
return sc;
}

the problem with this code is that after calling retrieveChannel()
some data arrvies on the channel and is immediately read by the
thread that uses the selector to get all non-blocking io..

Now what have I done wrong?
It smells like a synchronization problem ..

Any hints for me? Or better solutions to the problem?


If you can buffer the entire gzip file in memory, do that, and point a
ByteArrayInputStream at the result. If not, create an InputStream subclass
that returns data from the socket and blocks when none is available. The
second is more complicated, of course, since it requires multiple threads
and some synchronization between them.



I can't buffer it in memory..
as size could be anything from 100KiB to 16 GiB
I was just hoping that switching would be possible to spare me the work
of implementing this workaround.
.



Relevant Pages

  • Re: the 3GB Switch?
    ... The Perils of Trying to Overcome the 2GB Memory ... Windows will not allow you to use more than 2GB for a single ... SolidWorks is written to take advantage of the 3GB switch. ...
    (comp.cad.solidworks)
  • Re: the 3GB Switch?
    ... The Perils of Trying to Overcome the 2GB Memory ... Windows will not allow you to use more than 2GB for a single ... SolidWorks is written to take advantage of the 3GB switch. ...
    (comp.cad.solidworks)
  • Re: 4GBs of RAM Miscount
    ... onboard video and yet it sounds like you have a better card plugged in, ... have you ever applied the switch to a SBS 2003 box? ... The idea is that /PAE allows the system to move the reserved space ... it increases the 'pointers' for memory handling to allow 32b systems ...
    (microsoft.public.windows.server.sbs)
  • Re: HLA malloc problem
    ... but I personally don't run SQL server or something that needs ... doing this in large memory systems. ... switch to 32-bit coding until Win95 appeared. ... Would someone who has decided to pick up assembly language know what ...
    (comp.lang.asm.x86)
  • Re: the 3GB Switch?
    ... The Perils of Trying to Overcome the 2GB Memory ... Windows will not allow you to use more than 2GB for a single ... SolidWorks is written to take advantage of the 3GB switch. ...
    (comp.cad.solidworks)