OCCI and non-blocking

I'd like to use the OCCI interface in a non-blocking mode. Does anyone have any experience with this? Looks like I need to use a combo of OCI and OCCI calls to set the OCI_HTYPE_SERVER handle with the OCI_ATTR_NONBLOCKING MODE. However, my stmt->executeQuery() method seems to be throwing an exceptions, which I would have though would have been the OCI_STILL_EXECUTING error, but it's not. The exeception is an "ORA-32103 error from OCI call". If I continue to do another stmt->executeQuery(), I eventually get an access exception.
Anyone have any code snippets using OCCI in non-blocking mode?

I use threads. ACE/TAO to be precise.
I have singleton class that manages the Oracle environment and connection as well as being a statement
factory.
Just have a thread perform your stmt->executeXXX() method and you will not need to worry about non-blocking.
That's how I do it and it works well.

Similar Messages

  • Blocking and non-blocking workflows

    How to specify a workflow to be blocking and non-blocking?
    Regards,
    Miguel

    When registering the custom workflow from Application Server Control (Enterprise Manager Web Site), you will see an option to specify whether the workflow is blocking:
    Application Server Control > Content > Custom Workflows
    Register Workflow
    * Name  
      Description  
    * Launch Event  
    * Cancel Event  
      Blocking
      Approvers Required

  • Both blocking and non-blocking io

    I'm wondering if this scenario is possible with the new nio classes:
    I have a caching server. Clients connect to the server and occasionally send requests for objects. I'd like to use the nio non-blocking APIs to detect that there is a read pending on a socket. However, once I detect this, I'd like to go into a blocking loop to process the request. After this done, I'd like to go back into non-blocking mode and wait for another request.
    It seems like this should be possible but the (woefully lacking) documentation isn't clear. Neither is the source code, apparently.
    I've got a test case working but I was hoping someone could validate for me that this is support behavior. It's done by waiting for the isReadable() key then calling socket.keyFor(selector).cancel(); and then socket.configureBlocking(true); The reads are then done in blocking mode until the request is done and then the socket is registered with the selector again.
    Thanks for any help on this.

    I have to ask why you would want to mix blocking and non-blocking I/O.
    The only reason you would (IMHO) want to use non-blocking I/O is in a highly concurrent system, to increase the maximum load a system can handle.
    The main reason you would want to use blocking I/O rather than non-blocking I/O would be to minimise the latency for a single request.
    Unfortunately, the two don't seem to mix together very well... by switching a thread to blocking, you decrease the latency for a single request, but increase latency for the other requests due to reduced resources available. Similarly, by switching to blocking, you are requiring a dedicated thread for that request, so limiting the number of concurrent requests that can be serviced.
    That is, it seems to me that using both blocking and non-blocking I/O introduces the weaknesses of both into the system, without gaining much of the benefits of either.
    The above aside, the method you gave looks like it would work as you expect, depending on what you are doing with thread creation/delegation. Did your test case work as expected?

  • Chaining WritableByteChannels and non-blocking I/O?

    Hello all,
    Suppose I want to implement a data transformation algorithm that works in chunks of say 4 bytes.
    The algorithm would hook into existing I/O paradigms for writing and reading data.
    Ignoring the transformation algorithm for now (it is actually irrelevant for my question), let's just I need to buffer data in 4-byte chunks.
    Since I want to make as little assumptions as possible about the decorated channel, BufferingWritableByteChannel needs to work channels in blocking and in non-blocking mode.
    When the decorated channel is in non-blocking mode, BuffereingWritableByteChannel may behave as in non-blocking mode itself, which is fine by me.
    However the problem is with the residual bytes: they do not get written until the close() method is called.
    I have implemented the close() method to be blocking (the while loop with the ugly yield() calls), so even when the decorated channel is in non-blocking mode everything will get written properly.
    However, writing potentially blocking calls (busy loops) in close() methods seems like a bad idea...
    So the question is:
    Is there a better way of doing this?
    Can I avoid having to write busy loops?
    package nio;
    import java.io.IOException;
    import java.nio.ByteBuffer;
    import java.nio.channels.WritableByteChannel;
    import static nio.ChannelUtils.*;
    public class BufferingWritableByteChannel implements WritableByteChannel {
      private final WritableByteChannel decoratedChannel;
      private final ByteBuffer buffer = ByteBuffer.allocate(4);
      private boolean buffering = true;
      public BufferingWritableByteChannel(WritableByteChannel decoratedChannel) {
        this.decoratedChannel = decoratedChannel;
      public synchronized void close() throws IOException {
        if (buffering) {
          buffer.flip();
        writeBlockingly(decoratedChannel, buffer);
        buffer.clear();
        decoratedChannel.close();
      public synchronized boolean isOpen() {
        return decoratedChannel.isOpen();
      public synchronized int write(ByteBuffer input) throws IOException {
        int bytesWritten = 0;
        if (!buffering) {
          decoratedChannel.write(buffer);
          if (buffer.hasRemaining()) { // May happen when decorated channel in non-blocking mode
            return bytesWritten;
          buffer.clear();
          buffering = true;
        while (input.hasRemaining()) {
          bytesWritten += putAsMuchAsPossible(input, buffer);
          if (!buffer.hasRemaining()) {
            buffer.flip();
            decoratedChannel.write(buffer);
            if (buffer.hasRemaining()) { // May happen when decorated channel in non-blocking mode
              buffering = false;
              return bytesWritten;
            buffer.clear();
        return bytesWritten;
    package nio;
    import java.io.IOException;
    import java.nio.BufferOverflowException;
    import java.nio.ByteBuffer;
    import java.nio.channels.WritableByteChannel;
    public class ChannelUtils {
      private ChannelUtils() {
       * Blockingly writes data to a channel, even if the channel is in non-blocking mode.
      public static final int writeBlockingly(WritableByteChannel channel, ByteBuffer buffer) throws IOException {
        int bytesWritten = 0;
        boolean yield = false;
        while (buffer.hasRemaining()) {
          bytesWritten += channel.write(buffer);
          if (yield)
            Thread.yield();
          else
            yield = true;
        return bytesWritten;
       * Puts as much bytes as possible from an input buffer into an output buffer, avoiding {@link BufferOverflowException}.
      public static final int putAsMuchAsPossible(ByteBuffer input, ByteBuffer output) {
        int bytesWritten = Math.min(input.remaining(), output.remaining());
        ByteBuffer inputSlice = input.slice();
        inputSlice.limit(inputSlice.position() + bytesWritten);
        output.put(inputSlice);
        input.position(input.position() + bytesWritten);
        return bytesWritten;
    }

    Hello all,
    Suppose I want to implement a data transformation algorithm that works in chunks of say 4 bytes.
    The algorithm would hook into existing I/O paradigms for writing and reading data.
    Ignoring the transformation algorithm for now (it is actually irrelevant for my question), let's just I need to buffer data in 4-byte chunks.
    Since I want to make as little assumptions as possible about the decorated channel, BufferingWritableByteChannel needs to work channels in blocking and in non-blocking mode.
    When the decorated channel is in non-blocking mode, BuffereingWritableByteChannel may behave as in non-blocking mode itself, which is fine by me.
    However the problem is with the residual bytes: they do not get written until the close() method is called.
    I have implemented the close() method to be blocking (the while loop with the ugly yield() calls), so even when the decorated channel is in non-blocking mode everything will get written properly.
    However, writing potentially blocking calls (busy loops) in close() methods seems like a bad idea...
    So the question is:
    Is there a better way of doing this?
    Can I avoid having to write busy loops?
    package nio;
    import java.io.IOException;
    import java.nio.ByteBuffer;
    import java.nio.channels.WritableByteChannel;
    import static nio.ChannelUtils.*;
    public class BufferingWritableByteChannel implements WritableByteChannel {
      private final WritableByteChannel decoratedChannel;
      private final ByteBuffer buffer = ByteBuffer.allocate(4);
      private boolean buffering = true;
      public BufferingWritableByteChannel(WritableByteChannel decoratedChannel) {
        this.decoratedChannel = decoratedChannel;
      public synchronized void close() throws IOException {
        if (buffering) {
          buffer.flip();
        writeBlockingly(decoratedChannel, buffer);
        buffer.clear();
        decoratedChannel.close();
      public synchronized boolean isOpen() {
        return decoratedChannel.isOpen();
      public synchronized int write(ByteBuffer input) throws IOException {
        int bytesWritten = 0;
        if (!buffering) {
          decoratedChannel.write(buffer);
          if (buffer.hasRemaining()) { // May happen when decorated channel in non-blocking mode
            return bytesWritten;
          buffer.clear();
          buffering = true;
        while (input.hasRemaining()) {
          bytesWritten += putAsMuchAsPossible(input, buffer);
          if (!buffer.hasRemaining()) {
            buffer.flip();
            decoratedChannel.write(buffer);
            if (buffer.hasRemaining()) { // May happen when decorated channel in non-blocking mode
              buffering = false;
              return bytesWritten;
            buffer.clear();
        return bytesWritten;
    package nio;
    import java.io.IOException;
    import java.nio.BufferOverflowException;
    import java.nio.ByteBuffer;
    import java.nio.channels.WritableByteChannel;
    public class ChannelUtils {
      private ChannelUtils() {
       * Blockingly writes data to a channel, even if the channel is in non-blocking mode.
      public static final int writeBlockingly(WritableByteChannel channel, ByteBuffer buffer) throws IOException {
        int bytesWritten = 0;
        boolean yield = false;
        while (buffer.hasRemaining()) {
          bytesWritten += channel.write(buffer);
          if (yield)
            Thread.yield();
          else
            yield = true;
        return bytesWritten;
       * Puts as much bytes as possible from an input buffer into an output buffer, avoiding {@link BufferOverflowException}.
      public static final int putAsMuchAsPossible(ByteBuffer input, ByteBuffer output) {
        int bytesWritten = Math.min(input.remaining(), output.remaining());
        ByteBuffer inputSlice = input.slice();
        inputSlice.limit(inputSlice.position() + bytesWritten);
        output.put(inputSlice);
        input.position(input.position() + bytesWritten);
        return bytesWritten;
    }

  • Troubles with timeout using java.nio.channels and non-blocking sockets

    Hello.
    I have a server application that employs java.nio.channels with non-blocking sockets.
    The server waits for connections. The client should connect and be first in sending data.
    Timeouts are significant! If client exceeds the allowed time to send data, the server should break the connection.
    The huge trouble I've discovered that I cannot control the timeout when client connects but remains silent.
    My code looks as follows:
    <pre>
    Selector oSel;
    SocketChannel oSockChan;
    Socket oSock;
    SelectionKey oSelKey;
    Iterator<SelectionKey> oItSelKeys;
    int iCurrState, iMask, iCount;
    iCurrState = INT_SERVER_WORKING;
    iMask = SelectionKey.OP_ACCEPT | SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE;
    while ( iCurrState == INT_SERVER_WORKING )
    try
    *// retrieving next action*
    iCount = oSel.select();
    if ( iCount > 0 )
    oItSelKeys = oSel.selectedKeys().iterator();
    while ( oItSelKeys.hasNext() )
    oSelKey = oItSelKeys.next();
    oItSelKeys.remove();
    if ( oSelKey.isValid() )
    switch ( oSelKey.readyOps() & iMask ) {
    case SelectionKey.OP_ACCEPT :
    oSockChan = oSSockChan.accept();
    oSockChan.configureBlocking(false);
    oSock = oSockChan.socket();
    oSock.setKeepAlive(true);
    oSockChan.register(oSel,SelectionKey.OP_READ,new MyPacket(oSock.getInetAddress(),oSock.getPort()));
    break;
    case SelectionKey.OP_READ :
    oSelKey.interestOps(0);
    ((MyPacket) oSelKey.attachment()).inRequest(); *// preparing request*
    this.getReader().add(oSelKey); *// sending key to reading thread*
    break;
    case SelectionKey.OP_WRITE :
    oSelKey.interestOps(0);
    ((MyRequest) oSelKey.attachment()).inResponse(); *// preparing response*
    this.getWriter().add(oSelKey); *// sending key to writing thread*
    break;
    case SelectionKey.OP_CONNECT :
    default :
    *// nothing to do*
    catch ( IOException oExcept )
    *// do some actions*
    </pre>
    Timeouts are easily controlled by reading and writing threads (see OP_READ and OP_WRITE ).
    But when a client just connects without consequent data send, the state of this connection remains as OP_ACCEPT. The connection remains open for arbitrarily large time and I cannot control it!
    Please help with idea how can I terminate such connections!

    How can I process the keys that weren't selected at the bottom of the loop? Should I use the method keys() ?Yes. Form a new set from keys() and removeAll(selectedKeys()). Do that before you process selectedKeys().
    And the second moment: as I understood a single key may contain several operations simultaneously? Thus I should use several if's (but not if/else 'cause it's the equivalent of switch ... case ).If there is anything unclear about 'your switch statement is invalid. You need an if/else chain' I fail to see what it is. Try reading it again. And if several ifs were really the equivalent of "switch ... case", there wouldn't be a problem in the first place. They're not, and there is.

  • FileInputStream.read()  and non-blocking file i/o

    According to the API, FileInputStream.read() is :
    public native int read() throws IOException
    Reads a byte of data from this input stream. This method blocks if no input is yet available.
    Returns:
    the next byte of data, or -1 if the end of the file is reached.In what instances does the read() blocks? Is there a danger that the call to read() would block forever?

    thanks martian!
    is the ff code right enough to prevent i/o blocking?
      FileInputStream fis = new FileInputStream(src);
      FileOutputStream fos = new FileOutputStream(sPersistorFolder+src.getName());
      if(fis.available() > 0) {
        int c = -1;
        while((c=fis.read()) != -1) {
          fos.write(c);
      fis.close();
      fos.close();

  • SQL Developer blocking vs non-blocking

    Hi,
    Is there a way in SQL Developer 3.0 to have a non-blocking SQL call? In Oracle Forms we can choose between blocking and non-blocking SQL Net connections to the database. Does SQL Developer have the same capability? If so where exactly are those options hidden in the preferences menus?
    Annoyed,
    ScottK
    Edited by: ScottK on Jun 1, 2011 11:20 AM

    Hi ScottK,
    SQLDeveloper locks access to individual connections when they are in use, if you want to simulate
    some aspects of non blocking behaviour you can use other connections.
    The following features might help:
    Use a different connection name back to the same schema in your database - it will be treated as an independent connection and 'blocking' on this connection will not affect your other connections.
    This can be achieved temporarily in the worksheet by:
    ctrl shift n
    which creates a worksheet with new connection independent of your existing worksheet connection
    though connected to the same schema and database.
    -Turloch
    SQLDeveloper team

  • Non-blocking SocketChannels

    I'm trying to learn how to use non-blocking socket channles, but I haven't found much info (nor luck) so far.
    To learn, I'm building a server and a client. The server accepts input from the clients and process it in only one thread. The clients should send Objects to the server, and the server process them and return the result also as an Object. For this, I'm trying to use ObjectOutputStream and ObjectInputStream.
    The problem I don't know how to solve is that the SocketChannel is in non-bolcking mode, so I can't use their input/output streams (I get a IllegalBlockingModeException). In the server process loop I can reconfigure the SocketChannel to blocking mode to be able to read the Object, but I can't configure it to non-blocking mode again because I get a CancelledKeyException.
    Does anyone know how to work with InputStreams and non-blocking channels? Or where to find more info about it?
    Here are the relevant part of the server code:
    Set ready = selector.selectedKeys();
    Iterator i = ready.iterator();
    while (i.hasNext()) {
       try {
          SelectionKey sk = i.next();
          i.remove();
          if (sk.isAcceptable()) {
             ServerSocketChannel ssc = (ServerSocketChannel)sk.channel();
             SocketChannel sc = ssc.accept();
             sc.configureBlocking(false);
             sc.register(selector, SelectionKey.OP_READ);
          } else if (sk.isReadable()) {
             SocketChannel sc = (SocketChannel)sk.channel();
             // PROBLEM: If the channel is in non-blocking mode
             // I cannot use InputStreams
             sk.cancel();
             sc.configureBlocking(true);
             // Read the object sent by the client
             ObjectInputStream in = new ObjectInputStream(Channels.newInputStream(sc));
             Object o = in.readObject();
             // PROBLEM: Can't put the channel back to non-blocking mode
             sc.configureBlocking(false);
             sc.register(selector, SelectionKey.OP_READ); // CancelledKeyException
       } catch (...){
    }

    In my client, this is working fine:
    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;
    for (int i = 0; i < 30000; i++) {
       oos = new ObjectOutputStream(sc.socket().getOutputStream());
       oos.writeObject(object);
       oos.flush();
       ois = new ObjectInputStream(sc.socket().getInputStream());
       Object o = ois.readObject();
    }But trying to do it like this throws a StreamCorruptedException at the server side.
    ObjectOutputStream oos = new ObjectOutputStream(sc.socket().getOutputStream());
    ObjectInputStream ois = new ObjectInputStream(sc.socket().getInputStream());
    for (int i = 0; i < 30000; i++) {
       oos.writeObject(object);
       oos.flush();
       Object o = ois.readObject();
    }Do you know why?

  • Multiple non-blocking selectors in threads

    About networking in java and sockets i read alot. I know about the 2 implementations witk thread per client and non-blocking IO (usage of select()). I ran a few tests of my own and i could't decide. So I wrote a server that uses them both. The Ideea is to have no more than 100 clients per each selector and each selector runs in a thread. so when you have 4000 clients you actualy have 40 threads running each 100 clients:D
    However I'm stuck. I wrote this piece of code that has 2 objects one work thread with his own selector and a main thread with an accepting selector. The problem is that when I connect to it via telnet it only works when there is an even number of clients:(( when client nr 1 connects it blocks on channel.register(workSelector,SelectionKey.OP_READ);when client 2 gets connected it works:((
    HELP!!!
    here is the
    import java.nio.*;
    import java.nio.channels.*;
    import java.nio.charset.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.concurrent.ConcurrentHashMap;
    //work thread with own selector
    class workThread implements Runnable{
         public int userCount=0;
         public int ID=0;
         private Charset charset;
         private CharsetEncoder encoder;
         private CharsetDecoder decoder;
         private ByteBuffer buffer;
         private ConcurrentHashMap userMap;
         public Selector workSelector = null;
         public void addClient(SelectableChannel channel, int ops) throws IOException{
              if (channel == null) return;
              //channel.configureBlocking(false);
              System.out.println("Channel was added in workSelector : "+channel);
              channel.register(workSelector,SelectionKey.OP_READ);
              System.out.println("Client was added in work selector : " + ID);
              userCount++;
              System.out.println("Client nr : "+userCount);
         public boolean find(String name){
              return true;
         public workThread() throws IOException{
              charset = Charset.forName("ISO-8859-1");
              encoder = charset.newEncoder();
              decoder     = charset.newDecoder();     
              buffer = ByteBuffer.allocate(256);
    //          System.out.println("S-a creat selectorul");
              workSelector = Selector.open();
              System.out.println("Selector open ");
         private void doRead(SelectionKey key) throws IOException{
              SocketChannel clientChannel = (SocketChannel)key.channel();
              buffer.clear();
              System.out.println("Speaking to client");
              if(clientChannel.read(buffer) == -1){
                   key.cancel();
                   clientChannel.close();
              }else{
                   buffer.flip();
                   String message = decoder.decode(buffer).toString();
                   System.out.println(message);
                   if(message.trim().equals(".")){
                        clientChannel.write(encoder.encode(CharBuffer.wrap("BYE")));
                        key.cancel();
                        clientChannel.close();
                   }else{
                        buffer.flip();
                        clientChannel.write(buffer);
         private void doWrite(SelectionKey key){
              System.out.println("WRITE!!!");
         public void run(){
              while(true){
                   try{
                   if(workSelector.select() > 0){
                        Set keys1 = workSelector.selectedKeys();
                        for(Iterator itr = keys1.iterator();itr.hasNext();){
                             SelectionKey key = (SelectionKey)itr.next();
                             itr.remove();
                             if(key.isReadable()) {doRead(key);}
                        //     if(key.isWritable()) {doWrite(key);}
              }catch(IOException e){
                   System.out.println("Error in workthread "+ID+" "+e);
    //main thread
    public class msselect implements Runnable{
         private ServerSocketChannel server;
         private ServerSocket sock;
         private Selector acceptSelector;
         private workThread wk;
         public static void main(String args[]){
              try{
              msselect x = new msselect("80.97.89.73",6500,5);
              new Thread(x).start();
              }catch(IOException ex){
                   System.out.println("Probleme"+ex);
         msselect(String host, int port, int numT) throws IOException{
              server = ServerSocketChannel.open();
              sock = server.socket();
              sock.bind(new InetSocketAddress(port));
              server.configureBlocking(false);
              acceptSelector = Selector.open();
              server.register(acceptSelector, SelectionKey.OP_ACCEPT);
    /*          for(int i=0;i<numT;i++){
                   wk[i] = new workThread();
                   wk.ID = i;
                   new Thread(wk[i]).start();
              wk = new workThread();
              wk.ID = 1;
              server.register(wk.workSelector, SelectionKey.OP_ACCEPT);
              new Thread(wk).start();
         public void run(){
              while(true){
                   try{
                   acceptSelector.select();
                   Set keys = acceptSelector.selectedKeys();
                   for(Iterator itr = keys.iterator();itr.hasNext();){
                        SelectionKey key = (SelectionKey)itr.next();
                        itr.remove();
                        if(key.isAcceptable()){
                             SocketChannel client = null;
                             client = server.accept();
                             client.configureBlocking(false);
                             System.out.println("Accepted "+client);
                             wk.addClient(client,SelectionKey.OP_READ);
              }catch(IOException e){
                   System.out.println("Main Thread error"+e);

    I compiled and ran your code.
    The call channel.register(...) should block while selector is blocked in workSelector.select(). The fact that the registration succeeds is that you registered the server channel with both the work selector and the acceptor selector. The work selector is returning from select() because of a new client connection is accepted and is a matter of thread scheduling that the client.register() succeeeds (but only sometimes).
    Possible solution:
    - don't register the server channel with the work selector;
    - probably call workSelector.wakeup() to make the client channel registration possible.

  • What is the difference between non-blocking and 1:1 oversubscribed?

    Could someone tell me what the difference is between a non-blocked port and one with 1:1 oversubscription?

    "non-blocking port" and "1:1 oversubscription" are the same.    It's also the same when you are saying "line rate".  

  • Non-blocking and terminating processes

    Can someone give me an example of using the host.nonblocking to terminate a process or a window that is opened using a webutil_file_Transfer.DB_To_Client when finished using the opened document.
    I am using oracle 10g developer:
    Thanks

    "non-blocking port" and "1:1 oversubscription" are the same.    It's also the same when you are saying "line rate".  

  • Problem in Execute query on non-database block and database block together

    Hi All,
    In my form,i have
    1. First block is Non-database block with one non-database item.
    2. Second and third blocks are database blocks.
    Now the problem is that i want to perform execute-query for all the blocks.
    If the cursor is on the non-database item of 1st block and i clicks on the "Enter-query" then i am getting message " This function can not be performed here".
    If i click on the item of the database block and then clicks on the "Enter-query" and then "execute-query" it's working fine.
    But i don't want to do in this way.
    My cursor will be on the First block only and then it should perform execute-query.
    I am using this non-database item to copy value of this item to the item of the database block item.
    I think i make you understand about my problem.
    I am using forms 10g on Window xp.
    Please help me.

    Hi!
    Simply create a enter-query trigger on the non-database-block:
    begin
    go_block ( 'database_block' );
    enter_query;
    end;If your search criteria is in the non-database-item in the first block,
    you actually do not need the enter_query build-in.
    Just create a execute-query trigger on the first block like:
    begin
    go_block ( 'database_block' );
    execute_query;
    go_item ( :System.trigger_item );
    end;And in a pre-query trigger on the database-block copy the
    value of your seach item into the item you want to search for.
    Regards

  • Non-Blocking Writing and Strings

    Hello.
    My question is simple, is it possible to write strings using a non-blocking method?
    I was praying that there was a method in the NIO API that allowed me to, yet i can't find one.
    If the answer is blatantly obvious please forgive me, i'm tired and hungry :)
    Thank you for looking at this topic

    Strings are written to files or sockets using a certain encoding. I usually use UTF-8, but your application might be different.
    1. Get the SocketChannel from your non-blocking socket.
    SocketChannel ch = mySocket.getChannel(); // mySocket is java.net.Socket2. Make a CharBuffer out of the String you want to send.
    CharBuffer chars = CharBuffer.wrap(myString); // myString is your data3. Encode it so it becomes a ByteBuffer. I'll use the [UTF-8|http://www.joelonsoftware.com/articles/Unicode.html] Charset here.
    ByteBuffer bytes = Charset.forName("UTF-8").encode(chars);4. Use the write(ByteBuffer) method in the SocketChannel from 1.
    ch.write(bytes);Import declarations:
    import java.nio.channels.SocketChannel;
    import java.nio.CharBuffer;
    import java.nio.ByteBuffer;
    import java.nio.charset.Charset;s

  • Non-blocking SocketChannel and close - huh?

    It looks like closing a socketchannel that is in non-blocking mode can result in a dead drop of the connection, with some bytes that have already been sent and accepted (as in, 'consumed' from the buffer) being completely dropped.
    In fact, I'm generally confused: Actual C non-blocking code has a similar setup for 'close' as you can see in SocketChannel's OP_CONNECT behaviour - just because you want to connect the socket doesn't mean it magically happends without blocking. Wait for a ready flag, then try again.
    It should work the same way with close (you try to close, but it may not be possible without blocking).
    Is this a huge gaping bug that no one quite figured out just yet, or did I miss something? I loathe to turn on linger, as that's just a crapshoot (you never know if it actually gets through. You could run into funny surprises once the server gets a bit busy. I'd rather not) and tends to cause massive leaks on linux, at least according to some google searches.
    There seems to be slightly better performance (in that I have always received all data sofar) if I close the socket instead of the channel (socketChannel.socket().close() instead of socketChannel.close()) - but this has been a random attempt at 'making it work', and I can't find any documentation that backs up that this will DEFINITELY not lose any information without letting me know somehow. That still sounds impossible with this approach.

    Actual C non-blocking code has a similar setup for
    'close' as you can see in SocketChannel's
    OP_CONNECT behaviour ...No it doesn't. I don't know what you mean by this.
    Closing a socket is asynchronous, but it shouldn't lose any data - if the data can be delivered it will be, followed by the FIN. You don't know when it is delivered, and you don't get to hear about any errors such as an RST coming from the other end, say if it decided to close before reading all the data, or if some intermediate router hung you up.
    I'm wondering if you are really dealing with all the short write and zero length write possibilities, i.e. whether the data isn't really still in your output buffer. Don't wish to teach you to suck eggs but there are some subtleties here.
    Setting a positive linger timeout doesn't really help because Java doesn't tell you if the timeout expired. (I only asked for this about four years ago). You get to wait while any pending data is delivered, but you still have to guess about whether it all went or the timeout expired, and the behaviour after the timeout expires is platform-dependent: some (Windows) issue an RST, others (Unix) keep trying.
    Blocking or non-blocking mode shouldn't make any difference to this (except that Linux will block on a positive linger timeout even in non-blocking mode, which is wrong), and whether you close the channel or the socket is immaterial as one calls the other anyway.
    The reason why OP_CONNECT is different in blocking/non-blocking modes is that in blocking mode it won't return until the SYN-ACK is received, while in non-blocking mode it just sends the SYN and relies on you calling connect() again (at the C level) to collect the SYN-ACK, or not - this is what finishConnect() tells you.
    tends to cause massive leaks on linux, at least
    according to some google searchesIt can't, unless you are referring to the Helix client thing, which appears to be just a badly designed C++ class library with, for some reason, its own linger implementation outside the kernel.

  • ORA-03118 two-task error while doing a non blocking OCI call

    Hi,
    I have an application that runs on Linux and uses OCI API (version 8.1.6).
    If I do the following in non blocking mode after polling about
    70 times I get the error:
    ORA-03118: two-task coroutine has invalid state
    do {
    call_cnt++;
    rtc = OCIStmtFetch(stmtptr->stmt, oracle_err, 1, OCI_FETCH_NEXT,
    OCI_DEFAULT);
    } while (rtc == OCI_STILL_EXECUTING);
    This doesn't happen all the time but it happens most often on big selects.
    Does anyone have any idea what is happening here?
    I have searched for related information but have come up dry. If anyone
    knows anything or maybe a better place to ask this question please tell me.
    Thanks,
    Barry
    null

    Ask your basis guys to increase the table space...
    check this thread...
    [Error : DBIF_RSQL_SQL_ERROR;
    --- Thanks...

Maybe you are looking for

  • File Name and Path special field

    Post Author: puser01 CA Forum: .NET I have a report created in CR 9 with the File Name and Path special field on the report displayed correctly. when i try to run it on CR XI environment i get this: C:\WINDOWS\TEMP\{4D86438D-54F5-4EEF-A0AB-05D5EB2BFF

  • How to properly make a copy of Mountain Lion on a USB flash drive?

    Please Help! I tried to do the manual copy of Mountain Lion on my SanDisk cruzer blade 8gb flash drive but every time Disk Utility "finishes" the restore it displayes the following message: 'Failure Restore' Could not restore - Invalid argument. I tr

  • PCSuite : unable to access to Sync Parameters !

    Hello everybody, here is some informations which can help Windows Vista Business Nokia PC Suite 6.83.14.1 (french version) Nokia N70 Music Edition (Microsoft Outlook 2007) I use PC Suite mainly to sync my Outlook Calendar&Contacts with my N70. It is

  • Format Date

    Hi I've created a field of Date type. and It store the values as YYYY-MM-DD How can I view the date as DD-MM-YYYY ? I'm using Dreamweaver MX MySQl/PHP <?php echo $row_rsgrad['date_hiring']; ?>

  • LMS 4.2 upgrade to 4.2.1

    Hi, I'm in the process of upgrading from 4.1 to 4.2.3 sequentially and I've come across a problem. Yesterday all was well in going from 4.1 to 4.2 but today after going from 4.2 to 4.2.1 I'm unable to login and get the error. This happens both with m