Non blocking IO in jdk1.2??

hi All,
I would like to know what all non blocking IO operations are available to me in jdk1.2.2 which I can use in URLConnection. Would really appreciate help from all you people :)
Thanks in advance,
Rishi

Fluffy is correct but there are work arounds.
There are two methods available() for InputStream and ready() for Reader
The first one returns you an integer - if 0, then there are no bytes to read.
The second returns a boolean - if false, there is nothing to read.
Ironluca

Similar Messages

  • Non blocking sockets

    Hi All,
    Anybody have some idea about how to implement non blocking sockets using two threads/Can u help me with some sites where i can get more information in this topic.
    Regards
    Priya

    hi,
    you could have a look at the nonblocking io (nio) api's present in jdk1.4, that should do the trick. this link ought to get u started i suppose..
    http://developer.java.sun.com/developer/technicalArticles/releases/nio/
    hope this helps.
    cheerz
    ynkrish

  • Non-Blocking Multicast Sockets in JDK 1.4?

    Hi,
    I've been trying to create non-blocking multicast sockets in JDK1.4, which essentially seems (at this stage) to boil down to the simpler problem of creating a DatagramChannel that uses MulticastSockets, or at least DatagramSockets that can join a Multicast group. Not having found any obvious way to do it, I created this extraordinary hack:
    package java.net; // Wicked, wicked!
    import java.io.*;
    public class MyDatagramSocket {
    public static void join(java.net.DatagramSocket socket, InetAddress addr)
    throws IOExceptio DatagramSocket ds = new DatagramSocket(port);
    ds.setReuseAddress(true);
    MyDatagramSocket.join(ds, InetAddress.getByName("224.0.0.104"));
    DatagramPacket dp = new DatagramPacket(array, 5000);
    ds.receive(dp);          /* READS FINE */
    n
    socket.impl.join(addr); // Uses knowledge of DatagramSocket culled from examining source to access DatagramSocketImpl
    Now I compile this, and drop the class file into my rt.jar files (in the JDK and the JRE), so that I can use MyDatagramSocket.join (DatagramSocket, InetAddress), which looks like it should work from code like this:
    try {
    int port = 58501;
    DatagramChannel dc = DatagramChannel.open();
    dc.socket().setReuseAddress(true);
    dc.socket().bind(new InetSocketAddress(port));
    MyDatagramSocket.join(dc.socket(), InetAddress.getByName("224.0.0.104"));
    byte [] array = new byte[5000];
    ByteBuffer bb = ByteBuffer.wrap(array);
    dc.receive(bb);
    System.out.println("Read from dc");
    } catch (Exception x) {
    x.printStackTrace();
    But it doesn't work - it just doesn't read. A simpler example is this:
    DatagramSocket ds = new DatagramSocket(port);
    ds.setReuseAddress(true);
    MyDatagramSocket.join(ds, InetAddress.getByName("224.0.0.104"));
    DatagramPacket dp = new DatagramPacket(array, 5000);
    ds.receive(dp);          /* READS FINE */
    So I know that my hack is working, but this fails:
    DatagramChannel dc = DatagramChannel.open();
    dc.socket().bind(new InetSocketAddress(port));
    dc.socket().setReuseAddress(true);
    MyDatagramSocket.join(dc.socket(), InetAddress.getByName("224.0.0.104"));
    DatagramPacket dp = new DatagramPacket(array, 5000);
    dc.socket().receive(dp);     /* NEVER READS */
    I've reduced the problem to one of the difference between a java.net.DatagramSocket - the standard DatagramSocket, and a sun.nio.ch.DatagramSocketAdaptor, which is what DatagramChannels seem to use.
    My questions are:
    a) Is there a proper way to do this, without my adding my own classes to java.net?
    b) If NO is the answer to a), any ideas what I'm doing wrong in my code?
    Many thanks for any assistance,
    Craig

    I've encountered the same problem in my code. The datagramChannel never receives incoming data. Doesn't matter the rate at which you send it or anything else. I don't see any way around this problem at the moment. If i find something i'll post it. Interesting enough, my friend who programs with C++ got non-blocking I/O with datagrams to work in windows. So this might just be java.

  • NIO Non-Blocking Server not Reading from Key

    I have created a NIO non blocking server (below) and it will not pick up any input from the client.... My log doesnt even show that it enters the readKey() method, so it must be something before. Any help would be appreciated.
    Scott
    package jamb.server;
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.nio.ByteBuffer;
    import java.nio.CharBuffer;
    import java.nio.channels.ClosedChannelException;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.ServerSocketChannel;
    import java.nio.channels.SocketChannel;
    import java.nio.channels.spi.SelectorProvider;
    import java.nio.charset.Charset;
    import java.nio.charset.CharsetDecoder;
    import java.util.Iterator;
    import java.util.Set;
    import java.util.logging.Logger;
    import java.util.prefs.Preferences;
    import jamb.server.client.Client;
    public class Server {
            private Selector selector;
            private ServerSocketChannel serverChannel;
            private static Logger logger = Logger.getLogger("jamb.server");
            private static Preferences prefs =  Preferences.systemRoot().node("/jamb/server");
            public void init() {
                    logger.entering("jamb.server.Server", "init");
                    //Get a selector...
                    try {
                            selector = SelectorProvider.provider().openSelector();
                            //Open the SocketChannel and make it non-blocking...
                            serverChannel = ServerSocketChannel.open();
                         serverChannel.configureBlocking(false);
                            //Bind the server to the port....
                            int port = prefs.getInt("Port", 4000);
                            logger.config("Server configured on port " + port + " (default: 4000)");
                         InetSocketAddress isa = new InetSocketAddress(
                                    InetAddress.getLocalHost(), port);       
                         serverChannel.socket().bind(isa);
                    } catch (IOException ioe) {
                            logger.severe ("IOException during server initialization!");
                    logger.exiting("jamb.server.Server", "init");
            public void run() {
                    logger.entering("jamb.server.Server", "run");
                    int bufferSize = prefs.getInt("BufferSize", 8);
                    logger.config("Buffer size set to " + bufferSize + " (default: 8)");
                    SelectionKey acceptKey = null;
                    try {
                            acceptKey = serverChannel.register(
                                    selector, SelectionKey.OP_ACCEPT);
                    } catch (ClosedChannelException cce) {
                    try {
                            while (acceptKey.selector().select() > 0) {
                                    Set readyKeys = selector.selectedKeys();
                                    Iterator i = readyKeys.iterator();
                                    while (i.hasNext()) {
                                            //logger.finest("Processing keys...");
                                            //Get the key from the set and remove it
                                            SelectionKey currentKey = (SelectionKey) i.next();
                                            i.remove();
                                            if (currentKey.isAcceptable()) {
                                                    logger.finest("Accepting key...");
                                                    acceptKey(currentKey);
                                            } else if (currentKey.isReadable()) {
                                                    logger.finest("Reading key...");
                                                    readKey(currentKey, bufferSize);
                                            } else if (currentKey.isWritable()) {
                                                    //logger.finest("Writing key...");
                                                    writeKey(currentKey);
                    } catch (IOException ioe) {
                            logger.warning("IOException during key handling!");
                    logger.exiting("jamb.server.Server", "run");
            public void flushClient (Client client) {
                    try {
                            ByteBuffer buf = ByteBuffer.wrap( client.getOutputBuffer().toString().getBytes());
                            client.getChannel().write(buf);
                    } catch (IOException ioe) {
                            System.out.println ("Error writing to player");
                    client.setOutputBuffer(new StringBuffer());
            private void acceptKey (SelectionKey acceptKey) {
                    logger.entering("jamb.server.Server", "acceptKey");
                    //Retrieve a SocketChannel for the new client, and register a new selector with
                    //read/write interests, and then register
                    try {
                            SocketChannel channel =  ((ServerSocketChannel) acceptKey.channel()).accept();
                            channel.configureBlocking(false);
                            SelectionKey readKey = channel.register(
                                    selector, SelectionKey.OP_READ|SelectionKey.OP_WRITE  );
                            readKey.attach(new Client(this, channel));
                    } catch (IOException ioe) {
                            System.out.println ("Error accepting key");
                    logger.exiting("jamb.server.Server", "acceptKey");
            private void readKey (SelectionKey readKey, int bufSize) {
                    logger.entering("jamb.server.Server", "readKey");
                    Client client = (Client) readKey.attachment();
                    try {
                            ByteBuffer byteBuffer = ByteBuffer.allocate(bufSize);
                            int nbytes = client.getChannel().read( byteBuffer );
                            byteBuffer.flip();
                            Charset charset = Charset.forName( "us-ascii" );
                            CharsetDecoder decoder = charset.newDecoder();
                            CharBuffer charBuffer = decoder.decode(byteBuffer);
                            String text = charBuffer.toString();
                            client.getInputBuffer().append(text);
                            if ( text.indexOf( "\n" ) >= 0 )
                                    client.input();
                    } catch (IOException ioe) {
                            logger.warning("Unexpected quit...");
                            client.disconnect();
                    logger.exiting("jamb.server.Server", "readKey");
            private void writeKey (SelectionKey writeKey) {
                    //logger.entering("jamb.server.Server", "writeKey");
                    Client client = (Client) writeKey.attachment();
                    if (!client.isConnected()) {
                            client.connect();
                    //logger.exiting("jamb.server.Server", "writeKey");

    From my own expierence with the NIO (Under Windows XP/ jdk1.4.1_01); you can't seem to set READ and WRITE at the same time.
    The program flow I usually end up with for a echo server is:
    When the selector.isAcceptable(): accept a connection; register for READs
    In the read event; write the incoming characters to a buffer; register for a WRITE and add the buffer as an attachment.
    In the write event; write the data to the socket If all the data was written; register for a READ; otherwise register for another WRITE so that you can write the rest.
    Not sure if that the "proper" way; but it works well for me.
    - Chris

  • Non-blocking socket concurrent limitation?

    I have 2 socket program,one is server side used nio package with JDK1.4.1,the other is client used traditional socket,the client will initialize about 50
    threads trying to connect with server when starting,but only about 15
    can be accepted,these 2 program are runnning in the same computer which
    OS is win2000 professional PC.
    the followd is these code:
    please make a probe with them ,and tell me what's going on?
    server:
    package nio_select_demo;
    import java.io.*;
    import java.net.*;
    import java.nio.*;
    import java.nio.channels.*;
    import java.util.*;
    import java.nio.charset.Charset;
    import java.nio.charset.CharsetDecoder;
    public class Server implements Runnable
    // The port we will listen on
    private int port;
    // A pre-allocated buffer for processing data
    private final ByteBuffer buffer = ByteBuffer.allocate( 16384 );
    private ByteBuffer resBuf = ByteBuffer.allocate( 128 );
    Selector selector;
    AddInfo test ;
    public Server( int port ) {
    this.port = port;
    // for (int i=0; i<threadnum; ++i) {
    new Thread( this ).start();
    test = new AddInfo();
    test.start();
    public void run() {
    try {
    // create a ServerSocketChannel
    ServerSocketChannel ssc1 = ServerSocketChannel.open();
    // ServerSocketChannel ssc2 = ServerSocketChannel.open();
    // Set it to non-blocking
    ssc1.configureBlocking( false );
    // Get the Socket connected to this channel, and bind it
    // to the listening port
    ServerSocket ss = ssc1.socket();
    InetSocketAddress isa = new InetSocketAddress( port );
    ss.bind( isa , 60 );
    // Create a new Selector for selecting
    selector = Selector.open();
    // Register the ServerSocketChannel, so we can
    // listen for incoming connections
    ssc1.register( selector, SelectionKey.OP_ACCEPT );
    System.out.println( "Listening on port "+port );
    int n = 0;
    while (true) {
    // See if we've had any activity -- either
    // an incoming connection, or incoming data on an
    // existing connection
    int num = selector.select();
    // If we don't have any activity, loop around and wait
    // again
    if (num == 0) {
    continue;
    // Get the keys corresponding to the activity
    // that has been detected, and process them
    // one by one
    Set keys = selector.selectedKeys();
    Iterator it = keys.iterator();
    while (it.hasNext()) {
    // Get a key representing one of bits of I/O
    // activity
    SelectionKey key = (SelectionKey)it.next();
    // What kind of activity is it?
    if ((key.readyOps() & SelectionKey.OP_ACCEPT) ==
    SelectionKey.OP_ACCEPT) {
    System.out.println( "accept request" );
    // It's an incoming connection.
    // Register this socket with the Selector
    // so we can listen for input on it
    SocketChannel sc = ((ServerSocketChannel)key.channel()).accept();
    System.out.println( "Got connection from "+sc.socket());
    // Make sure to make it non-blocking, so we can
    // use a selector on it.
    //SocketChannel sc = s.getChannel();
    sc.configureBlocking( false );
    // Register it with the selector, for reading
    sc.register( selector, SelectionKey.OP_READ| SelectionKey.OP_WRITE);
    } else if ((key.readyOps() & SelectionKey.OP_READ) ==
    SelectionKey.OP_READ) {
    //ssc.register(selector , SelectionKey.OP_READ);
    SocketChannel sc = null;
    try {
    // It's incoming data on a connection, so
    // process it
    sc = (SocketChannel)key.channel();
    Socket s1 = sc.socket();
    s1.setTcpNoDelay(true);
    System.out.println( "enter processing data" );
    boolean ok = processInput( key );
    synchronized (selector) {
    key.interestOps(key.interestOps() & ~SelectionKey.OP_READ);
    // If the connection is dead, then remove it
    // from the selector and close it
    if (!ok) {
    key.cancel();
    System.out.println("dead");
    Socket s = null;
    try {
    s = sc.socket();
    s.close();
    } catch( IOException ie ) {
    System.err.println( "Error closing socket "+s+": "+ie );
    } catch( IOException ie ) {
    ie.printStackTrace();
    // On exception, remove this channel from the selector
    key.cancel();
    System.err.println( "Error raised in this socket");
    try {
    sc.close();
    } catch( IOException ie2 ) { System.out.println( ie2 ); }
    System.out.println( "Closed "+sc );
    else if ((key.readyOps() & SelectionKey.OP_WRITE) ==
    SelectionKey.OP_WRITE) {
    System.out.println("Enter Writing");
    String response = new String();
    if((response=this.test.getInfo())!=null){
    resBuf.clear();
    SocketChannel sc = (SocketChannel)key.channel();
    resBuf = ByteBuffer.wrap( response.getBytes("ISO-8859-1" ) );
    sc.write( resBuf );
    synchronized (selector) {
    key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE);
    // We remove the selected keys, because we've dealt
    // with them.
    keys.clear();
    } catch( IOException ie ) {
    System.err.println( ie );
    private boolean processInput( SelectionKey key ) throws IOException {
    buffer.clear();
    SocketChannel sc = (SocketChannel)key.channel();
    sc.read( buffer );
    buffer.flip();
    String response = new String("response ok");
    // If no data, close the connection
    if (buffer.limit()==0) {
    return false;
    Charset charset=Charset.forName("ISO-8859-1");
    CharsetDecoder decoder = charset.newDecoder();
    CharBuffer charBuffer = decoder.decode(buffer);
    System.out.println(charBuffer.toString());
    System.out.println( "Processed "+buffer.limit()+" from "+sc );
    return true;
    static public void main( String args[] ) throws Exception {
    int port = Integer.parseInt( args[0] );
    System.out.println(port);
    new Server( port );
    cilent:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Client implements Runnable
    private String host;
    private int port;
    private int acport;
    //the size of buffer on how much we write and read per cycle
    private static final int maxWriteSize = 128;
    public Client( String host, int port, int numThreads ) {
    this.host = host;
    this.port = port;
    for(int i =0;i<50;i++){//initialize 50 client threads
    new Thread(this).start();
    public void run() {
    byte buffer[] = new byte[maxWriteSize];
    byte buffer2[] = new byte[maxWriteSize];
    try {
    Socket s = new Socket( );
    InetSocketAddress sa = new InetSocketAddress(host,this.port);
    s.connect(sa);
    System.out.println(s);
    s.setTcpNoDelay(true);
    InputStream in = s.getInputStream();
    OutputStream out = s.getOutputStream();
    for (int i=0; i<maxWriteSize; ++i) {
    buffer[i] = (byte)'a';
    out.write( buffer, 0, maxWriteSize );
    int pause = 500;
    in.read( buffer , 0 , maxWriteSize );
    System.out.println( Thread.currentThread()+" wrote "+maxWriteSize);
    String res = new String ( buffer );
    String res2 = new String ( buffer2 );
    System.out.println( res );
    try { Thread.sleep( pause ); } catch( InterruptedException ie ) {}
    } catch( Exception ie ) {
    ie.printStackTrace();
    System.err.println(ie.getMessage());
    static public void main( String args[] ) throws Exception {
    String host = "127.0.0.1";
    int port = Integer.parseInt( args[0] );
    int numThreads = Integer.parseInt( args[1] );
    new Client( host, port, numThreads );

    I have found the reason!!!
    because of system resource limitation,windows can't afford to maintain
    so many concurrent stream-IO,so some socket will be closed.
    I modified the client side code,adding thes segments to client instantialize
    such as :
    public Client( String host, int port, int numThreads ) {
    for(int i =0;i<1000;i++){
    new Thread(this).start();
    try {
    Thread.currentThread().sleep(100);//give system some idle
    } catch (InterruptedException e) {
    /* ignore */
    then the server can accept more than 1000 client request concurrently.

  • JDK 1.4 nio non-blocking connects don't finish

    I am working with the Linux version of JDK1.4, doing some testing of the
    non-blocking capability. The few tests that I have done have shown some
    strange results:
    - When opening a non-blocking connection to a server which has an
    announcement banner, say such as POP which gives something like:
    +OK pop3 server ready
    then connection seems to be OK and proceed through to completion.
    - When opening a non-blocking connection to a server which is silent, and
    expects me to start the conversation, such as contacting an HTTP server,
    then the Selector.select() never returns to allow me to finish the
    connection.
    Below is a test program which illustrates the problem for me.
    It attempts to open a non-blocking connection to www.yahoo.com on port 80.
    It then drops into a Selector.select() where I am waiting for the chance to
    catch the SelectionKey.OP_CONNECT event and finish connecting, and then send
    a simple HTTP GET request down the wire. That OP_CONNECT event
    never seems to arrive though, and I remain stuck in the select().
    'netstat -na' shows that I am in a connection established state.
    Any insight appreciated,
    -Steve M [email protected]
    ------------------>8 cut here 8<-----------------------
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.nio.*;
    import java.nio.channels.*;
    public class NoWorkee
    public static String GET_REQUEST = "GET / HTTP/1.0\r\n\r\n";
        static class Context
            String host;
            int    port;
            ByteBuffer request;
            public Context (String h, int p, ByteBuffer r)
            {host=h; port=p; request=r;}
    Selector sel = null;
    boolean keepGoing = true;
    public NoWorkee()
        throws IOException
        sel = Selector.open();
    public void add(String host, int port)
        throws IOException
        int ops = SelectionKey.OP_CONNECT;
        // create non-blocking socket, and initiate connect operation
        SocketChannel sc = SocketChannel.open();
        sc.configureBlocking(false);
        sc.connect(new InetSocketAddress(InetAddress.getByName(host), port));
        SelectionKey sk;
        try
            sk = sc.register(sel, ops);
            System.out.println ( "sc.register looks good connected=" +
                sc.isConnected() + ", isConnectionPending=" +
                sc.isConnectionPending());
            sk.attach(new Context(host, port, ByteBuffer.wrap(GET_REQUEST.getBytes())));
        catch (IOException x)
            x.printStackTrace();
            sc.close();
    public void run()
        throws IOException
        keepGoing = true;
        System.out.println ( "Selecting " + sel.keys().size() + " SelectKeys");
        while (keepGoing)
            final long before = System.currentTimeMillis();
            final int numReady = sel.select();
            //final int numReady = sel.select(1000);
            final long after = System.currentTimeMillis();
            System.out.println ( "Blocked " + (after-before) + " ms, numReady=" + numReady);
            if (numReady > 0)
                Set readyKeys = sel.selectedKeys();
                System.out.println ( "Selected keys size " + readyKeys.size());
                for (Iterator it = readyKeys.iterator(); it.hasNext();)
                    SelectionKey sk = (SelectionKey)it.next();
                    SocketChannel sockChan = (SocketChannel)sk.channel();
                    Context ctx = (Context)sk.attachment();
                    System.out.println ( "Servicing host " + ctx.host + " port "
                                 ctx.port);
    System.out.println ( "1");
                    if (sk.isConnectable())
                        if (sockChan.finishConnect())
                            System.out.println ( "Finished connecting success "
    + sockChan);
                            int ops = SelectionKey.OP_READ | SelectionKey.OP_WRITE;
                            sk.interestOps (ops);
                        else
                            System.out.println ( "Could not finishConnect for "
                                sockChan);
                            sk.cancel();
                            sockChan.close();
    System.out.println ( "2");
                    if (sk.isAcceptable())
                        System.out.println ( "in sk.isAcceptable() block");
    System.out.println ( "3");
                    if (sk.isReadable())
                        System.out.println ( "in sk.isReadable() block");
                        byte rawBuff[] = new byte[32 * 1024];
                        ByteBuffer buff = ByteBuffer.wrap(rawBuff);
                        int numRead = -1;
                        while (0 < (numRead = sockChan.read(buff)))
                            System.out.println ( "numRead = " + numRead);
                            for (int i = 0; i < numRead; i++)
                                System.out.print((char)rawBuff);
    System.out.println ( "numRead = " + numRead);
    System.out.println ( "4");
    if (sk.isWritable())
    System.out.println ( "in sk.isReadable() block");
    int numWritten = -1;
    if (null != ctx.request)
    numWritten = sockChan.write(ctx.request);
    if (!ctx.request.hasRemaining())
    sk.interestOps(sk.interestOps() &
    ~SelectionKey.OP_WRITE);
    System.out.println ( "numWritten = " + numWritten);
    //else
    // service timeouts
    public static void main (String arg[])
    try
    NoWorkee bla = new NoWorkee();
    bla.add ("www.yahoo.com", 80);
    bla.run();
    catch (Exception e)
    e.printStackTrace();
    ------------------>8 cut here 8<-----------------------

    Just for the benefit of anyone who might be seeing the same problem, it looks like bug 4457776 accurately describes the problem that I was having above.
    I am downloading j2sdk-1_4_0-beta2-linux-i386-rpm.bin to see if that fixed it.
    Reference:
    http://developer.java.sun.com/developer/bugParade/bugs/4457776.html

  • 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

  • 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...

  • 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".  

  • Implementing non-blocking read

    Hi all
    I have some doubts about implementing non-blocking io in my application.
    I am using Jsch library (an ssh implementation) to open an ssh connection with a host. The API only provides me with methods to open a connection and retreive the input & output streams. I want to make my read on inputstream non-blocking.In such a case is it possible to use nio for the purpose?
    If it's not possible then I am planning to use threading to make read() non-blocking. Here also i need some clarifications. I am planning to use a ThreadPoolExecutor to create a thread pool for reading data. SO whenever i have a read i'll assign this task to the pool which will use one of the free threads to execute the inputStresm.read().
    Now the question is if one of the threads in this pool blocks forever during a read since it didn't get any response from the other side, is there a way to stop that read and make that thread free again to execute more tasks? or will the thread block forever till the application is closed?
    In my case i cannot afford to have too many such blocked threads, since this application will not be restarted very often. Once it is started it can go on for may be days or months.
    Please suggest what would be best in my case taking into account performance as most important factor.
    Thanks in advance.
    Anu

    endasil wrote:
    First of all, let me state that I agree with the others in saying that I don't fully agree with your premises.
    That said, I believe that this does a non-blocking read based on the contract of InputStream.available() and .read(byte[], int, int):
    private int nonBlockingRead(InputStream in, byte[] buffer) throws IOException {
    return in.read(buffer, 0, Math.min(in.available(), buffer.length));
    If the InputStream is obtained from a JSSE socket then it is my understanding that available() always returns zero. This is allowed under the InputStream.available() contract as defined in the Javadoc - http://java.sun.com/javase/6/docs/api/java/io/InputStream.html#available() . If I am right then your code will never read anything from a JSSE socket InputStream and I would suspect that Jsch is using JSSE sockets.

  • Application Builder: Can you create non-blocking, return-immediately functions in a dll?

    I need to include a procedure in a dll that is non-blocking, i.e. it should return immediately after the procedure has been called, and not return after its processes are completed.
    The procedure is a LabView 7.0 VI, and the dll is being created using the Application Builder. Currently the procedure completes its desired task and then returns, but I would like the function to return immediately. Thanks for your help!

    Rischaard,
    I don't know if that will work in a dll, however as an idea:
    use the vi-server functions:
    Your dll-procedure opens a OwnTreat.vi(wich will do the work) with vi-server, and run it without waiting for completion.
    First thing OwnTreat.vi should do is opening (with vi-server) a reference to itself (So your caller dll can close without stopping the OwnTreat.vi)
    Then OwnTreat.vi con do what YOU want. When finished close the self-reference
    Maybe you need a short wait or a feedback to make sure that OwnTreat has opened his own reverence before your dll stops.
    Greetings from Germany
    Henrik
    LV since v3.1
    “ground” is a convenient fantasy
    '˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

  • 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".  

  • Using OCIBindDynamic with non-blocking connections

    I need to use an OCI array interface for execute statements more than once per one request to server.
    When I have called stored procedure or function in the non-blocking connection context using OCIBindDynamic for parameter binding, application have been crashed at random time.
    I don't have any problems using default (blocking) mode.
    Environment:
    Oracle 8.1.7 release 3 for Windows
    MS Visual C++ 6.0 compiler
    Could anybody help me ?

    It's always possible in any read that the number of bytes read is less than the number of bytes requested. You need to keep reading until you have got everything you expected, and cope with every possible error condition on each iteration.
    EJP

  • NIO: Strange problem when using ByteBuffer with non-blocking SocketChannel

    Hi,
    I have a server that uses multiplexed, non-blocking I/O with java.nio. When a client connects, the server waits for the message: <system cmd="knock"/>, returns a message and disconnects the client. The clients are shortly serviced in less than a second.
    But the server newer receive anything from about 20% of the clients - even though it is sent. Or with other words: it is received and the data is contained in the ByteBuffer - SocketChannel.read(ByteBuffer) - but a call to ByteBuffer.remaing() returns 0 !!
    ByteBuffer receiveBuf = ByteBuffer.allocate(65536);
    receiveBuf.clear(); // the code is elsewhere used for longer living clients
    int readBytes = channel.read(receiveBuf);
    receiveBuf.flip();
    StringBuffer sb = new StringBuffer();
    System.out.println(" * Remaining: "+receiveBuf.remaining()); // writes: ' * Remaining: 0'
    System.out.println(" * Received: "+new String(receiveBuf.array())); // writes: ' * Received: <system cmd="knock"/>'
    while(receiveBuf.remaining() >= 2) {
      byte b = receiveBuf.get();
      sb.append((char)b);
    System.out.println(" * sb content: "+sb.toString()); // writes: ' * sb content: 'The ByteBuffer clearly receives the correct data, but the ByteBuffer.remaining() returns 0 and therefore the StringBuffer will never have any content.
    The problem seems to occur randomly and for about 20% of the clients (simulated from the same computer and therefore has the same bandwidth and so on).
    Anyone knows what is going on, and how to solve the problem !?

    It's always possible in any read that the number of bytes read is less than the number of bytes requested. You need to keep reading until you have got everything you expected, and cope with every possible error condition on each iteration.
    EJP

  • SELECT of OCILobLocator in Non Blocking mode

    Hi all.
    I have problem:
    I try select BLOB field into OCILobLocator* buffer in Non Blocking mode, and receive 'ORA-03106: fatal two-task communication protocol error' sometimes.
    Details:
    Application contains two threads : 1. select blob field, 2. update it.
    I tried separate update and select to different apps (and run its in one time) - problem reproduced.
    problem reproduced for OCIStmtFetch and OCIStmtFetch2.
    If disable non blocking mode - problem disappear.
    if error appear - record level error code contains 1405. Need wait few minutes for error message appearing (~1 minute in my case).
    Using of OCI_DEFAULT in OCIDefineByPos instead OCI_DYNAMIC_FETCH don't solve problem.
    I use oracle server and client library with version 10.2.0.4
    Output sample:
    execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
    ', error code = 3106, row errors: #877: 1405
    execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
    ', error code = 3106, row errors: #54: 1405
    execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
    ', error code = 3106, row errors: #877: 1405
    execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
    ', error code = 3106, row errors: #54: 1405
    Can anybody help me ?
    m.b. exists workaround ?
    #include <iostream>
    #include <sstream>
    #include <assert.h>
    #include <oci.h>
    #define _DYN 1
    before run this test run next sql at DB:
    CREATE TABLE ADSERVERTEST_BLOB(id NUMBER(10), text BLOB);
    BEGIN
    FOR i IN 0..999 LOOP
    INSERT INTO ADSERVERTEST_BLOB(id, text) VALUES(i, utl_raw.cast_to_raw('init'));
    END LOOP;
    END;
    template<typename Type, unsigned long TypeId>
    class OCIHandlePtr
    public:
    OCIHandlePtr(): handle_(0) {}
    OCIHandlePtr(Type* handle): handle_(handle) {}
    ~OCIHandlePtr()
    reset(0);
    void reset(Type* handle)
    if(handle_)
    sword result;
    if((result = OCIHandleFree(
    handle_,
    TypeId)) != OCI_SUCCESS)
    assert(0);
    std::cerr << "Can't make OCIHandleFree" << std::endl;
    handle_ = handle;
    Type* get()
    return handle_;
    Type*& fill()
    reset(0);
    return handle_;
    private:
    Type* handle_;
    template<typename Type, unsigned long TypeId>
    class OCIDescriptorPtr
    public:
    OCIDescriptorPtr(): handle_(0) {}
    OCIDescriptorPtr(Type* handle): handle_(handle) {}
    ~OCIDescriptorPtr()
    reset(0);
    void reset(Type* handle)
    if(handle_)
    sword result;
    if((result = OCIDescriptorFree(
    handle_,
    TypeId)) != OCI_SUCCESS)
    std::cerr << "Can't make OCIDescriptorFree" << std::endl;
    handle_ = handle;
    Type* get()
    return handle_;
    Type*& fill()
    reset(0);
    return handle_;
    private:
    Type* handle_;
    void throw_oci_error(
    const char* fun,
    const char* oci_op,
    long status,
    OCIError* oci_error_handler,
    const char* query = 0)
    std::cerr << fun << ": can't make " << oci_op << ": status = " << status;
    if(status == OCI_SUCCESS_WITH_INFO ||
    status == OCI_ERROR)
    std::cerr << ", message = '";
    text err_buf[1024] = "";
    sb4 err_code = 0;
    OCIErrorGet(
    oci_error_handler,
    (ub4)1,
    0,
    &err_code,
    err_buf,
    sizeof(err_buf),
    (ub4)OCI_HTYPE_ERROR);
    std::cerr << err_buf << "', error code = " << err_code;
    exit(1);
    if(query)
    std::cerr << ", sql = " << query;
    OCIHandlePtr<OCIEnv, OCI_HTYPE_ENV> environment_handle;
    void connect(
    OCIEnv* environment_handle,
    const char* db,
    const char* user,
    const char* password,
    OCIHandlePtr<OCIError, OCI_HTYPE_ERROR>& error_handle,
    OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER>& server_handle,
    OCIHandlePtr<OCISession, OCI_HTYPE_SESSION>& session_handle,
    OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX>& svc_context_handle)
    static const char* FUN = "connect()";
    sword result;
    // allocate an error handle
    if((result = OCIHandleAlloc(
    environment_handle,
    (void **) &error_handle.fill(),
    OCI_HTYPE_ERROR,
    0, // extra memory to allocate
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    // allocate a server handle
    if((result = OCIHandleAlloc(
    environment_handle,
    (void **) &server_handle.fill(),
    OCI_HTYPE_SERVER,
    0, // extra memory to allocate
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    if((result = OCIServerAttach(
    server_handle.get(),
    error_handle.get(),
    (text*)db,
    strlen(db),
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIServerAttach", result, error_handle.get());
    // allocate a service handle
    if((result = OCIHandleAlloc(
    environment_handle,
    (void **) &svc_context_handle.fill(),
    OCI_HTYPE_SVCCTX,
    0, // extra memory to allocate
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    // set the server attribute in the service context handle
    if((result = OCIAttrSet(
    svc_context_handle.get(),
    OCI_HTYPE_SVCCTX,
    server_handle.get(),
    sizeof(OCIServer*),
    OCI_ATTR_SERVER,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    // allocate a user session handle
    if((result = OCIHandleAlloc(
    environment_handle,
    (void **)&session_handle.fill(),
    OCI_HTYPE_SESSION,
    0, // extra memory to allocate
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    // set username and password attributes in user session handle
    if((result = OCIAttrSet(
    session_handle.get(),
    OCI_HTYPE_SESSION,
    (text*)user,
    strlen(user),
    OCI_ATTR_USERNAME,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
    if((result = OCIAttrSet(
    session_handle.get(),
    OCI_HTYPE_SESSION,
    (text*)password,
    strlen(password),
    OCI_ATTR_PASSWORD,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
    // start the session
    if((result = OCISessionBegin(
    svc_context_handle.get(),
    error_handle.get(),
    session_handle.get(),
    OCI_CRED_RDBMS,
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCISessionBegin", result, error_handle.get());
    // set the user session attribute in the service context handle
    if((result = OCIAttrSet(
    svc_context_handle.get(),
    OCI_HTYPE_SVCCTX,
    session_handle.get(),
    sizeof(OCISession*),
    OCI_ATTR_SESSION,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
    ub1 attr_value = 1;
    if((result = OCIAttrSet(
    server_handle.get(),
    OCI_HTYPE_SERVER,
    &attr_value,
    sizeof(attr_value),
    OCI_ATTR_NONBLOCKING_MODE,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
    void disconnect(
    OCIEnv* environment_handle,
    OCIError* error_handle,
    OCIServer* server_handle,
    OCISession* session_handle,
    OCISvcCtx* svc_context_handle)
    static const char* FUN = "disconnect()";
    sword result;
    if((result = OCISessionEnd(
    svc_context_handle,
    error_handle,
    session_handle,
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCISessionEnd", result, error_handle);
    if((result = OCIServerDetach(
    server_handle,
    error_handle,
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIServerDetach", result, error_handle);
    OCILobLocator* FETCH_BUFFER_1[10000*1024];
    char IND_BUFFER_1[10000*1024];
    ub2 ERROR_BUFFER_1[1024];
    OCIDefine* define_handle_1;
    void clear_blob_buf(
    OCILobLocator** buf,
    unsigned long fetch_size)
    for(unsigned long i = 0; i < 1024; ++i)
    OCIDescriptorFree(
    buf,
    (ub4)OCI_DTYPE_LOB);
    ::memset(buf, 0, fetch_size * 1024);
    uint32_t RET_LEN4;
    sb4 oci_blob_callback(
    dvoid* ctx,
    OCIDefine* define,
    ub4 iter,
    dvoid** bufpp,
    ub4** alenpp,
    ub1* piecep,
    dvoid** indpp,
    ub2** rcodepp)
    RET_LEN4 = sizeof(OCILobLocator*);
    *bufpp = FETCH_BUFFER_1[iter];
    *alenpp = &RET_LEN4;
    *piecep = OCI_ONE_PIECE;
    *indpp = IND_BUFFER_1 + iter;
    *rcodepp = ERROR_BUFFER_1 + iter;
    //std::cout << "iter: " << iter << std::endl;
    return OCI_CONTINUE;
    int define_column(
    OCIEnv* environment_handle,
    OCISvcCtx* svc_handle,
    OCIStmt* stmt_handle,
    OCIError* error_handle,
    OCIDefine** define_handle,
    unsigned long pos,
    long oci_type,
    unsigned long fetch_size,
    OCILobLocator** buf,
    char* ind_buf,
    ub2* err_buf)
    static const char* FUN = "define_column()";
    sword result;
    if(oci_type == SQLT_BLOB)
    ::memset(buf, 0, fetch_size * 1024);
    for(int i = 0; i < 1024; ++i)
    if((result = OCIDescriptorAlloc(
    (dvoid*)environment_handle,
    (dvoid**)&buf[i],
    (ub4)OCI_DTYPE_LOB,
    (size_t)0,
    (dvoid**)0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIDescriptorAlloc", result, error_handle);
    ub2 size = 0;
    OCIDescriptorPtr<OCIParam, OCI_DTYPE_PARAM> param_handle;
    // ub2 oci_data_type = 0;
    if((result = OCIParamGet(
    stmt_handle,
    OCI_HTYPE_STMT,
    error_handle,
    reinterpret_cast<void**>(&param_handle.fill()),
    pos)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIParamGet", result, error_handle);
    if((result = OCIAttrGet(
    param_handle.get(),
    OCI_DTYPE_PARAM,
    &size,
    0,
    OCI_ATTR_DATA_SIZE,
    error_handle)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrGet", result, error_handle);
    if((result = OCIDefineByPos(
    stmt_handle,
    define_handle,
    error_handle,
    pos,
    # ifdef _DYN
    0,
    -1,
    #else
    buf,
    fetch_size,
    #endif
    oci_type,
    ind_buf,
    0,
    err_buf, // ptr to array of column-level return codes
    # ifdef _DYN
    OCI_DYNAMIC_FETCH
    # else
    OCI_DEFAULT
    # endif
    )) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIDefineByPos", result, error_handle);
    # ifdef _DYN
    if((result = OCIDefineDynamic(
    *define_handle,
    error_handle,
    0,
    oci_blob_callback)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIDefineByPos", result, error_handle);
    # endif
    return 0;
    int define_columns(
    OCIEnv* environment_handle,
    OCISvcCtx* svc_handle,
    OCIStmt* stmt_handle,
    OCIError* error_handle)
    static const char* FUN = "define_columns()";
    define_handle_1 = 0;
    int pos = 1;
    ::memset(ERROR_BUFFER_1, 0, 1024 * sizeof(ERROR_BUFFER_1[0]));
    define_column(
    environment_handle,
    svc_handle,
    stmt_handle,
    error_handle,
    &define_handle_1,
    pos++,
    SQLT_BLOB,
    sizeof(OCILobLocator*),
    FETCH_BUFFER_1,
    IND_BUFFER_1,
    ERROR_BUFFER_1);
    return 0;
    int execute_select(
    const char* db,
    const char* user,
    const char* password)
    static const char* FUN = "execute_select()";
    const unsigned long FETCH_COUNT = 1024;
    OCIHandlePtr<OCIError, OCI_HTYPE_ERROR> error_handle;
    OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER> server_handle;
    OCIHandlePtr<OCISession, OCI_HTYPE_SESSION> session_handle;
    OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX> svc_context_handle;
    connect(
    environment_handle.get(),
    db,
    user,
    password,
    error_handle,
    server_handle,
    session_handle,
    svc_context_handle);
    OCIHandlePtr<OCIStmt, OCI_HTYPE_STMT> stmt_handle;
    sword result;
    if((result = OCIHandleAlloc(
    environment_handle.get(),
    (void**)&stmt_handle.fill(),
    OCI_HTYPE_STMT,
    0,
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    const char QUERY[] = "SELECT text FROM ADSERVERTEST_BLOB";
    ub4 rows = 0;
    if((result = OCIAttrSet(
    stmt_handle.get(),
    OCI_HTYPE_STMT,
    (dvoid *)&rows,
    (ub4)sizeof(ub4),
    OCI_ATTR_PREFETCH_ROWS,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(
    FUN, "OCIAttrSet(OCI_ATTR_PREFETCH_ROWS)", result, error_handle.get());
    if((result = OCIStmtPrepare(
    stmt_handle.get(),
    error_handle.get(),
    (text*)QUERY,
    strlen(QUERY),
    OCI_NTV_SYNTAX,
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIStmtPrepare", result, error_handle.get());
    ub2 stmt_type;
    if((result = OCIAttrGet(
    stmt_handle.get(),
    OCI_HTYPE_STMT,
    &stmt_type,
    0,
    OCI_ATTR_STMT_TYPE,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrGet", result, error_handle.get());
    ub4 prev_fetched = 0;
    while((result = OCIStmtExecute(
    svc_context_handle.get(),
    stmt_handle.get(),
    error_handle.get(),
    0,
    0,
    0,
    0,
    OCI_DEFAULT)) != OCI_SUCCESS)
    if(result != OCI_STILL_EXECUTING)
    throw_oci_error(FUN, "OCIStmtExecute", result, error_handle.get());
    define_columns(
    environment_handle.get(),
    svc_context_handle.get(),
    stmt_handle.get(),
    error_handle.get());
    ub4 all_fetched_count = 0;
    while(true)
    while((result = OCIStmtFetch2(
    stmt_handle.get(),
    error_handle.get(),
    FETCH_COUNT,
    OCI_FETCH_NEXT,
    1,
    OCI_DEFAULT)) == OCI_STILL_EXECUTING
    # ifdef _DYN
    // || result == OCI_NEED_DATA
    # endif
    if (result != OCI_SUCCESS &&
    result != OCI_NO_DATA &&
    result != OCI_SUCCESS_WITH_INFO)
    std::cerr << FUN << ": can't make OCIStmtFetch2: status = " << result;
    std::cerr << ", message = '";
    text err_buf[1024] = "";
    sb4 err_code = 0;
    OCIErrorGet(
    error_handle.get(),
    (ub4)1,
    0,
    &err_code,
    err_buf,
    sizeof(err_buf),
    (ub4)OCI_HTYPE_ERROR);
    std::cerr << err_buf << "', error code = " << err_code << ", row errors: ";
    for(const ub2* cur = ERROR_BUFFER_1;
    cur < ERROR_BUFFER_1 + 1024; ++cur)
    if(*cur)
    std::cerr << "#" << (cur - ERROR_BUFFER_1) << ": " <<
    *cur << std::endl;
    ub4 fetched_count = 0;
    if((result = OCIAttrGet (
    stmt_handle.get(),
    OCI_HTYPE_STMT,
    &fetched_count,
    0,
    OCI_ATTR_ROW_COUNT,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrGet", result, error_handle.get());
    all_fetched_count += fetched_count;
    if(fetched_count > 0)
    for(unsigned long i = 0; i < fetched_count - 1; ++i)
    ub4 lob_size;
    while((result = OCILobGetLength(
    svc_context_handle.get(),
    error_handle.get(),
    FETCH_BUFFER_1[i],
    &lob_size)) == OCI_STILL_EXECUTING)
    if(result != OCI_SUCCESS)
    throw_oci_error(FUN, "OCILobGetLength", result, error_handle.get());
    std::cout << "#" << i << ": ind = " << (unsigned long)IND_BUFFER_1[i] <<
    ", len = " << lob_size << std::endl;
    if(fetched_count - prev_fetched < FETCH_COUNT)
    break;
    prev_fetched = fetched_count;
    clear_blob_buf(
    FETCH_BUFFER_1,
    sizeof(OCILobLocator*));
    while((result = OCIStmtFetch(
    stmt_handle.get(),
    error_handle.get(),
    0,
    OCI_FETCH_NEXT,
    OCI_DEFAULT)) == OCI_STILL_EXECUTING
    disconnect(
    environment_handle.get(),
    error_handle.get(),
    server_handle.get(),
    session_handle.get(),
    svc_context_handle.get());
    return 0;
    int execute_update(
    const char* db,
    const char* user,
    const char* password)
    static const char* FUN = "execute_update()";
    OCIHandlePtr<OCIError, OCI_HTYPE_ERROR> error_handle;
    OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER> server_handle;
    OCIHandlePtr<OCISession, OCI_HTYPE_SESSION> session_handle;
    OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX> svc_context_handle;
    connect(
    environment_handle.get(),
    db,
    user,
    password,
    error_handle,
    server_handle,
    session_handle,
    svc_context_handle);
    OCIHandlePtr<OCIStmt, OCI_HTYPE_STMT> stmt_handle;
    for(int i = 0; i < 1000; ++i)
    sword result;
    if((result = OCIHandleAlloc(
    environment_handle.get(),
    (void**)&stmt_handle.fill(),
    OCI_HTYPE_STMT,
    0,
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    std::ostringstream sql;
    std::string str;
    std::string et("\xEB\xB2\x88");
    unsigned long rep = ::rand() % 500 + 1;
    str.reserve(rep*et.size());
    for(unsigned long ei = 0; ei < rep; ++ei)
    str.append(et);
    sql << "BEGIN " <<
    "UPDATE ADSERVERTEST_BLOB SET text = "
    "utl_raw.cast_to_raw('" << str << "') "
    "WHERE id = " << i <<
    "END;";
    if((result = OCIStmtPrepare(
    stmt_handle.get(),
    error_handle.get(),
    (text*)sql.str().c_str(),
    sql.str().length(),
    OCI_NTV_SYNTAX,
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIStmtPrepare", result, error_handle.get());
    while((result = OCIStmtExecute(
    svc_context_handle.get(),
    stmt_handle.get(),
    error_handle.get(),
    1,
    0,
    0,
    0,
    OCI_DEFAULT)) != OCI_SUCCESS)
    if(result != OCI_STILL_EXECUTING)
    throw_oci_error(FUN, "OCIStmtExecute", result, error_handle.get());
    disconnect(
    environment_handle.get(),
    error_handle.get(),
    server_handle.get(),
    session_handle.get(),
    svc_context_handle.get());
    return 0;
    void* select_thread(void* ctx)
    while(true)
    execute_select(
    "//oraclept.ocslab.com/addbpt.ocslab.com",
    "bs_unittest_4",
    "adserver");
    // std::cout << "select finished" << std::endl;
    return ctx;
    void* update_thread(void* ctx)
    while(true)
    execute_update(
    "//oraclept.ocslab.com/addbpt.ocslab.com",
    "bs_unittest_4",
    "adserver");
    // std::cout << "update finished" << std::endl;
    return ctx;
    int main()
    static const char* FUN = "main()";
    sword result;
    // allocate an environment handle
    if((result = OCIEnvCreate(
    &environment_handle.fill(),
    OCI_OBJECT | OCI_THREADED,
    0, // context
    0, // malloc
    0, // realloc
    0, // free
    0, // extra memory to allocate
    0) // pointer to user-memory
    ) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIEnvCreate", result, 0);
    pthread_t th1, th2;
    pthread_create(&th1, 0, select_thread, 0);
    pthread_create(&th2, 0, update_thread, 0);
    pthread_join(th1, 0);
    pthread_join(th2, 0);
    return 0;
    Edited by: user13011391 on 20.04.2010 5:50
    Edited by: user13011391 on 20.04.2010 6:00
    Edited by: user13011391 on 20.04.2010 6:15

    Hi all.
    I have problem:
    I try select BLOB field into OCILobLocator* buffer in Non Blocking mode, and receive 'ORA-03106: fatal two-task communication protocol error' sometimes.
    Details:
    Application contains two threads : 1. select blob field, 2. update it.
    I tried separate update and select to different apps (and run its in one time) - problem reproduced.
    problem reproduced for OCIStmtFetch and OCIStmtFetch2.
    If disable non blocking mode - problem disappear.
    if error appear - record level error code contains 1405. Need wait few minutes for error message appearing (~1 minute in my case).
    Using of OCI_DEFAULT in OCIDefineByPos instead OCI_DYNAMIC_FETCH don't solve problem.
    I use oracle server and client library with version 10.2.0.4
    Output sample:
    execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
    ', error code = 3106, row errors: #877: 1405
    execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
    ', error code = 3106, row errors: #54: 1405
    execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
    ', error code = 3106, row errors: #877: 1405
    execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
    ', error code = 3106, row errors: #54: 1405
    Can anybody help me ?
    m.b. exists workaround ?
    #include <iostream>
    #include <sstream>
    #include <assert.h>
    #include <oci.h>
    #define _DYN 1
    before run this test run next sql at DB:
    CREATE TABLE ADSERVERTEST_BLOB(id NUMBER(10), text BLOB);
    BEGIN
    FOR i IN 0..999 LOOP
    INSERT INTO ADSERVERTEST_BLOB(id, text) VALUES(i, utl_raw.cast_to_raw('init'));
    END LOOP;
    END;
    template<typename Type, unsigned long TypeId>
    class OCIHandlePtr
    public:
    OCIHandlePtr(): handle_(0) {}
    OCIHandlePtr(Type* handle): handle_(handle) {}
    ~OCIHandlePtr()
    reset(0);
    void reset(Type* handle)
    if(handle_)
    sword result;
    if((result = OCIHandleFree(
    handle_,
    TypeId)) != OCI_SUCCESS)
    assert(0);
    std::cerr << "Can't make OCIHandleFree" << std::endl;
    handle_ = handle;
    Type* get()
    return handle_;
    Type*& fill()
    reset(0);
    return handle_;
    private:
    Type* handle_;
    template<typename Type, unsigned long TypeId>
    class OCIDescriptorPtr
    public:
    OCIDescriptorPtr(): handle_(0) {}
    OCIDescriptorPtr(Type* handle): handle_(handle) {}
    ~OCIDescriptorPtr()
    reset(0);
    void reset(Type* handle)
    if(handle_)
    sword result;
    if((result = OCIDescriptorFree(
    handle_,
    TypeId)) != OCI_SUCCESS)
    std::cerr << "Can't make OCIDescriptorFree" << std::endl;
    handle_ = handle;
    Type* get()
    return handle_;
    Type*& fill()
    reset(0);
    return handle_;
    private:
    Type* handle_;
    void throw_oci_error(
    const char* fun,
    const char* oci_op,
    long status,
    OCIError* oci_error_handler,
    const char* query = 0)
    std::cerr << fun << ": can't make " << oci_op << ": status = " << status;
    if(status == OCI_SUCCESS_WITH_INFO ||
    status == OCI_ERROR)
    std::cerr << ", message = '";
    text err_buf[1024] = "";
    sb4 err_code = 0;
    OCIErrorGet(
    oci_error_handler,
    (ub4)1,
    0,
    &err_code,
    err_buf,
    sizeof(err_buf),
    (ub4)OCI_HTYPE_ERROR);
    std::cerr << err_buf << "', error code = " << err_code;
    exit(1);
    if(query)
    std::cerr << ", sql = " << query;
    OCIHandlePtr<OCIEnv, OCI_HTYPE_ENV> environment_handle;
    void connect(
    OCIEnv* environment_handle,
    const char* db,
    const char* user,
    const char* password,
    OCIHandlePtr<OCIError, OCI_HTYPE_ERROR>& error_handle,
    OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER>& server_handle,
    OCIHandlePtr<OCISession, OCI_HTYPE_SESSION>& session_handle,
    OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX>& svc_context_handle)
    static const char* FUN = "connect()";
    sword result;
    // allocate an error handle
    if((result = OCIHandleAlloc(
    environment_handle,
    (void **) &error_handle.fill(),
    OCI_HTYPE_ERROR,
    0, // extra memory to allocate
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    // allocate a server handle
    if((result = OCIHandleAlloc(
    environment_handle,
    (void **) &server_handle.fill(),
    OCI_HTYPE_SERVER,
    0, // extra memory to allocate
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    if((result = OCIServerAttach(
    server_handle.get(),
    error_handle.get(),
    (text*)db,
    strlen(db),
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIServerAttach", result, error_handle.get());
    // allocate a service handle
    if((result = OCIHandleAlloc(
    environment_handle,
    (void **) &svc_context_handle.fill(),
    OCI_HTYPE_SVCCTX,
    0, // extra memory to allocate
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    // set the server attribute in the service context handle
    if((result = OCIAttrSet(
    svc_context_handle.get(),
    OCI_HTYPE_SVCCTX,
    server_handle.get(),
    sizeof(OCIServer*),
    OCI_ATTR_SERVER,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    // allocate a user session handle
    if((result = OCIHandleAlloc(
    environment_handle,
    (void **)&session_handle.fill(),
    OCI_HTYPE_SESSION,
    0, // extra memory to allocate
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    // set username and password attributes in user session handle
    if((result = OCIAttrSet(
    session_handle.get(),
    OCI_HTYPE_SESSION,
    (text*)user,
    strlen(user),
    OCI_ATTR_USERNAME,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
    if((result = OCIAttrSet(
    session_handle.get(),
    OCI_HTYPE_SESSION,
    (text*)password,
    strlen(password),
    OCI_ATTR_PASSWORD,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
    // start the session
    if((result = OCISessionBegin(
    svc_context_handle.get(),
    error_handle.get(),
    session_handle.get(),
    OCI_CRED_RDBMS,
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCISessionBegin", result, error_handle.get());
    // set the user session attribute in the service context handle
    if((result = OCIAttrSet(
    svc_context_handle.get(),
    OCI_HTYPE_SVCCTX,
    session_handle.get(),
    sizeof(OCISession*),
    OCI_ATTR_SESSION,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
    ub1 attr_value = 1;
    if((result = OCIAttrSet(
    server_handle.get(),
    OCI_HTYPE_SERVER,
    &attr_value,
    sizeof(attr_value),
    OCI_ATTR_NONBLOCKING_MODE,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
    void disconnect(
    OCIEnv* environment_handle,
    OCIError* error_handle,
    OCIServer* server_handle,
    OCISession* session_handle,
    OCISvcCtx* svc_context_handle)
    static const char* FUN = "disconnect()";
    sword result;
    if((result = OCISessionEnd(
    svc_context_handle,
    error_handle,
    session_handle,
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCISessionEnd", result, error_handle);
    if((result = OCIServerDetach(
    server_handle,
    error_handle,
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIServerDetach", result, error_handle);
    OCILobLocator* FETCH_BUFFER_1[10000*1024];
    char IND_BUFFER_1[10000*1024];
    ub2 ERROR_BUFFER_1[1024];
    OCIDefine* define_handle_1;
    void clear_blob_buf(
    OCILobLocator** buf,
    unsigned long fetch_size)
    for(unsigned long i = 0; i < 1024; ++i)
    OCIDescriptorFree(
    buf,
    (ub4)OCI_DTYPE_LOB);
    ::memset(buf, 0, fetch_size * 1024);
    uint32_t RET_LEN4;
    sb4 oci_blob_callback(
    dvoid* ctx,
    OCIDefine* define,
    ub4 iter,
    dvoid** bufpp,
    ub4** alenpp,
    ub1* piecep,
    dvoid** indpp,
    ub2** rcodepp)
    RET_LEN4 = sizeof(OCILobLocator*);
    *bufpp = FETCH_BUFFER_1[iter];
    *alenpp = &RET_LEN4;
    *piecep = OCI_ONE_PIECE;
    *indpp = IND_BUFFER_1 + iter;
    *rcodepp = ERROR_BUFFER_1 + iter;
    //std::cout << "iter: " << iter << std::endl;
    return OCI_CONTINUE;
    int define_column(
    OCIEnv* environment_handle,
    OCISvcCtx* svc_handle,
    OCIStmt* stmt_handle,
    OCIError* error_handle,
    OCIDefine** define_handle,
    unsigned long pos,
    long oci_type,
    unsigned long fetch_size,
    OCILobLocator** buf,
    char* ind_buf,
    ub2* err_buf)
    static const char* FUN = "define_column()";
    sword result;
    if(oci_type == SQLT_BLOB)
    ::memset(buf, 0, fetch_size * 1024);
    for(int i = 0; i < 1024; ++i)
    if((result = OCIDescriptorAlloc(
    (dvoid*)environment_handle,
    (dvoid**)&buf[i],
    (ub4)OCI_DTYPE_LOB,
    (size_t)0,
    (dvoid**)0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIDescriptorAlloc", result, error_handle);
    ub2 size = 0;
    OCIDescriptorPtr<OCIParam, OCI_DTYPE_PARAM> param_handle;
    // ub2 oci_data_type = 0;
    if((result = OCIParamGet(
    stmt_handle,
    OCI_HTYPE_STMT,
    error_handle,
    reinterpret_cast<void**>(&param_handle.fill()),
    pos)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIParamGet", result, error_handle);
    if((result = OCIAttrGet(
    param_handle.get(),
    OCI_DTYPE_PARAM,
    &size,
    0,
    OCI_ATTR_DATA_SIZE,
    error_handle)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrGet", result, error_handle);
    if((result = OCIDefineByPos(
    stmt_handle,
    define_handle,
    error_handle,
    pos,
    # ifdef _DYN
    0,
    -1,
    #else
    buf,
    fetch_size,
    #endif
    oci_type,
    ind_buf,
    0,
    err_buf, // ptr to array of column-level return codes
    # ifdef _DYN
    OCI_DYNAMIC_FETCH
    # else
    OCI_DEFAULT
    # endif
    )) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIDefineByPos", result, error_handle);
    # ifdef _DYN
    if((result = OCIDefineDynamic(
    *define_handle,
    error_handle,
    0,
    oci_blob_callback)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIDefineByPos", result, error_handle);
    # endif
    return 0;
    int define_columns(
    OCIEnv* environment_handle,
    OCISvcCtx* svc_handle,
    OCIStmt* stmt_handle,
    OCIError* error_handle)
    static const char* FUN = "define_columns()";
    define_handle_1 = 0;
    int pos = 1;
    ::memset(ERROR_BUFFER_1, 0, 1024 * sizeof(ERROR_BUFFER_1[0]));
    define_column(
    environment_handle,
    svc_handle,
    stmt_handle,
    error_handle,
    &define_handle_1,
    pos++,
    SQLT_BLOB,
    sizeof(OCILobLocator*),
    FETCH_BUFFER_1,
    IND_BUFFER_1,
    ERROR_BUFFER_1);
    return 0;
    int execute_select(
    const char* db,
    const char* user,
    const char* password)
    static const char* FUN = "execute_select()";
    const unsigned long FETCH_COUNT = 1024;
    OCIHandlePtr<OCIError, OCI_HTYPE_ERROR> error_handle;
    OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER> server_handle;
    OCIHandlePtr<OCISession, OCI_HTYPE_SESSION> session_handle;
    OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX> svc_context_handle;
    connect(
    environment_handle.get(),
    db,
    user,
    password,
    error_handle,
    server_handle,
    session_handle,
    svc_context_handle);
    OCIHandlePtr<OCIStmt, OCI_HTYPE_STMT> stmt_handle;
    sword result;
    if((result = OCIHandleAlloc(
    environment_handle.get(),
    (void**)&stmt_handle.fill(),
    OCI_HTYPE_STMT,
    0,
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    const char QUERY[] = "SELECT text FROM ADSERVERTEST_BLOB";
    ub4 rows = 0;
    if((result = OCIAttrSet(
    stmt_handle.get(),
    OCI_HTYPE_STMT,
    (dvoid *)&rows,
    (ub4)sizeof(ub4),
    OCI_ATTR_PREFETCH_ROWS,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(
    FUN, "OCIAttrSet(OCI_ATTR_PREFETCH_ROWS)", result, error_handle.get());
    if((result = OCIStmtPrepare(
    stmt_handle.get(),
    error_handle.get(),
    (text*)QUERY,
    strlen(QUERY),
    OCI_NTV_SYNTAX,
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIStmtPrepare", result, error_handle.get());
    ub2 stmt_type;
    if((result = OCIAttrGet(
    stmt_handle.get(),
    OCI_HTYPE_STMT,
    &stmt_type,
    0,
    OCI_ATTR_STMT_TYPE,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrGet", result, error_handle.get());
    ub4 prev_fetched = 0;
    while((result = OCIStmtExecute(
    svc_context_handle.get(),
    stmt_handle.get(),
    error_handle.get(),
    0,
    0,
    0,
    0,
    OCI_DEFAULT)) != OCI_SUCCESS)
    if(result != OCI_STILL_EXECUTING)
    throw_oci_error(FUN, "OCIStmtExecute", result, error_handle.get());
    define_columns(
    environment_handle.get(),
    svc_context_handle.get(),
    stmt_handle.get(),
    error_handle.get());
    ub4 all_fetched_count = 0;
    while(true)
    while((result = OCIStmtFetch2(
    stmt_handle.get(),
    error_handle.get(),
    FETCH_COUNT,
    OCI_FETCH_NEXT,
    1,
    OCI_DEFAULT)) == OCI_STILL_EXECUTING
    # ifdef _DYN
    // || result == OCI_NEED_DATA
    # endif
    if (result != OCI_SUCCESS &&
    result != OCI_NO_DATA &&
    result != OCI_SUCCESS_WITH_INFO)
    std::cerr << FUN << ": can't make OCIStmtFetch2: status = " << result;
    std::cerr << ", message = '";
    text err_buf[1024] = "";
    sb4 err_code = 0;
    OCIErrorGet(
    error_handle.get(),
    (ub4)1,
    0,
    &err_code,
    err_buf,
    sizeof(err_buf),
    (ub4)OCI_HTYPE_ERROR);
    std::cerr << err_buf << "', error code = " << err_code << ", row errors: ";
    for(const ub2* cur = ERROR_BUFFER_1;
    cur < ERROR_BUFFER_1 + 1024; ++cur)
    if(*cur)
    std::cerr << "#" << (cur - ERROR_BUFFER_1) << ": " <<
    *cur << std::endl;
    ub4 fetched_count = 0;
    if((result = OCIAttrGet (
    stmt_handle.get(),
    OCI_HTYPE_STMT,
    &fetched_count,
    0,
    OCI_ATTR_ROW_COUNT,
    error_handle.get())) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIAttrGet", result, error_handle.get());
    all_fetched_count += fetched_count;
    if(fetched_count > 0)
    for(unsigned long i = 0; i < fetched_count - 1; ++i)
    ub4 lob_size;
    while((result = OCILobGetLength(
    svc_context_handle.get(),
    error_handle.get(),
    FETCH_BUFFER_1[i],
    &lob_size)) == OCI_STILL_EXECUTING)
    if(result != OCI_SUCCESS)
    throw_oci_error(FUN, "OCILobGetLength", result, error_handle.get());
    std::cout << "#" << i << ": ind = " << (unsigned long)IND_BUFFER_1[i] <<
    ", len = " << lob_size << std::endl;
    if(fetched_count - prev_fetched < FETCH_COUNT)
    break;
    prev_fetched = fetched_count;
    clear_blob_buf(
    FETCH_BUFFER_1,
    sizeof(OCILobLocator*));
    while((result = OCIStmtFetch(
    stmt_handle.get(),
    error_handle.get(),
    0,
    OCI_FETCH_NEXT,
    OCI_DEFAULT)) == OCI_STILL_EXECUTING
    disconnect(
    environment_handle.get(),
    error_handle.get(),
    server_handle.get(),
    session_handle.get(),
    svc_context_handle.get());
    return 0;
    int execute_update(
    const char* db,
    const char* user,
    const char* password)
    static const char* FUN = "execute_update()";
    OCIHandlePtr<OCIError, OCI_HTYPE_ERROR> error_handle;
    OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER> server_handle;
    OCIHandlePtr<OCISession, OCI_HTYPE_SESSION> session_handle;
    OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX> svc_context_handle;
    connect(
    environment_handle.get(),
    db,
    user,
    password,
    error_handle,
    server_handle,
    session_handle,
    svc_context_handle);
    OCIHandlePtr<OCIStmt, OCI_HTYPE_STMT> stmt_handle;
    for(int i = 0; i < 1000; ++i)
    sword result;
    if((result = OCIHandleAlloc(
    environment_handle.get(),
    (void**)&stmt_handle.fill(),
    OCI_HTYPE_STMT,
    0,
    0)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
    std::ostringstream sql;
    std::string str;
    std::string et("\xEB\xB2\x88");
    unsigned long rep = ::rand() % 500 + 1;
    str.reserve(rep*et.size());
    for(unsigned long ei = 0; ei < rep; ++ei)
    str.append(et);
    sql << "BEGIN " <<
    "UPDATE ADSERVERTEST_BLOB SET text = "
    "utl_raw.cast_to_raw('" << str << "') "
    "WHERE id = " << i <<
    "END;";
    if((result = OCIStmtPrepare(
    stmt_handle.get(),
    error_handle.get(),
    (text*)sql.str().c_str(),
    sql.str().length(),
    OCI_NTV_SYNTAX,
    OCI_DEFAULT)) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIStmtPrepare", result, error_handle.get());
    while((result = OCIStmtExecute(
    svc_context_handle.get(),
    stmt_handle.get(),
    error_handle.get(),
    1,
    0,
    0,
    0,
    OCI_DEFAULT)) != OCI_SUCCESS)
    if(result != OCI_STILL_EXECUTING)
    throw_oci_error(FUN, "OCIStmtExecute", result, error_handle.get());
    disconnect(
    environment_handle.get(),
    error_handle.get(),
    server_handle.get(),
    session_handle.get(),
    svc_context_handle.get());
    return 0;
    void* select_thread(void* ctx)
    while(true)
    execute_select(
    "//oraclept.ocslab.com/addbpt.ocslab.com",
    "bs_unittest_4",
    "adserver");
    // std::cout << "select finished" << std::endl;
    return ctx;
    void* update_thread(void* ctx)
    while(true)
    execute_update(
    "//oraclept.ocslab.com/addbpt.ocslab.com",
    "bs_unittest_4",
    "adserver");
    // std::cout << "update finished" << std::endl;
    return ctx;
    int main()
    static const char* FUN = "main()";
    sword result;
    // allocate an environment handle
    if((result = OCIEnvCreate(
    &environment_handle.fill(),
    OCI_OBJECT | OCI_THREADED,
    0, // context
    0, // malloc
    0, // realloc
    0, // free
    0, // extra memory to allocate
    0) // pointer to user-memory
    ) != OCI_SUCCESS)
    throw_oci_error(FUN, "OCIEnvCreate", result, 0);
    pthread_t th1, th2;
    pthread_create(&th1, 0, select_thread, 0);
    pthread_create(&th2, 0, update_thread, 0);
    pthread_join(th1, 0);
    pthread_join(th2, 0);
    return 0;
    Edited by: user13011391 on 20.04.2010 5:50
    Edited by: user13011391 on 20.04.2010 6:00
    Edited by: user13011391 on 20.04.2010 6:15

Maybe you are looking for