Non-blocking or wait-free Synchronisation for Java

Are there information or patterns about this topic? Who can help me ? Are there Books, Article, Papers and so on?

or Non-blocking or wait-free Synchronisation in general

Similar Messages

  • NIO non-blocking i/o- Any advantages for UDP server??

    Hi,
    I am developing a classic UDP-based server which serves hundreds of clients simultaneously. After receiving a simple request from a client, the server replies with a simple response (messages are no larger than 50 bytes).
    What, if any non-blocking-related advantages would there be in using nio? Specifically, if I used select() without turning on non-blocking on the data channel, what do I lose?
    The architecture consists of only one socket for responding to client requests. It uses receive() and send(), not read()/write()/connect().
    Thanks in advance,
    Dan.

    >>
    What, if any non-blocking-related advantageswould
    there be in using nio? Specifically, if I used
    select() without turning on non-blocking on thedata
    channel, what do I lose?You cannot do this. The runtime will throw an
    IllegalBlockingModeException when you tried to
    register it.
    So in order to use select(), your registered channels must
    be in non-blocking mode? Why? That's just the way it is?
    So to conclude, using non-blocking mode provides no real advantage for
    my application. It is only required or else I would not be able to use
    select(), right? If so, what is so good about nio? Can you give an example that is similar to my application which would benefit from the non-blocking characteristic of nio?
    Thanks for your help so far...
    Daniel.
    >>
    The architecture consists of only one socket for
    responding to client requests. It uses receive()and
    send(), not read()/write()/connect().If you are only reading from one socket there are
    theoretical advantages to servicing requests on more
    than one thread, but you would not use non-blocking
    mode to do this.
    However I think some operating systems have
    performance problems when doing this. Look at this
    article under accept serialization:
    http://httpd.apache.org/docs/misc/perf-tuning.html
    The same problems may apply to multi-thread udp socket
    readers.

  • Non-blocking read from an InputStream??

    Hello all, I have a bit of a problem. I have a GUI based app that, through the mindterm SSH classes, runs a "tail -f /var/log/somelog" command on a *nix server. The purpose of the app is to make looking through the log's easier for the non-computer lay-person. The problem is that if they click the stop button to stop the output of the tail it doesn't actually stop that thread until the next line is appended to the end of the log file. That could be a second or an hour. So what I need is a way to somehow stop that tail -f command when the user hits stop and not have to wait for the read to occur.
    What I'm working with is a com.mindbright.util.InputStreamPipe that is a subclass of java.io.InputStream. I've tried several things. Such as the seda.nbio.NonblockingInputStream which gives me a runtime classCastException when trying to cast the com.mindbright.util.InputStreamPipe to a seda.nbio.NonblockingInputStream. I've tried creating a java.nio.channels.ReadableByteChannel and using it's read method but that also blocks.
    So my question is, does anyone have any clever solutions to this particular problem? I thought the way to beat it was to find some mechanism to do a read that will just get passed by if there's nothing to read then have it wait an arbitrary amount of time before reading again. So the longest the user would have to wait would be that arbitrary amount of time. But I don't know how to implement this or if it's even a good way to do it.
    Thanks in advance!

    Thanks for the help dubwai. I actually found a way to accomplish this without any non-blocking balony.
    public void run () {
                            try {
                                    java.io.InputStream is = tbs.getConsoleOut();
                                    java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(is));
                                    String line = null;
                                    // continue is a volatile boolean that gets set to false when user clicks stop
                                    while ( cont ) {
                                            if ( is.available() > 0 ) {
                                                    line = in.readLine();
                                                    System.out.println("in while: "+line);
                                            } // end
                                            else {
                                                    try {
                                                            java.lang.Thread.sleep(500);
    } // end try
                                                    catch ( java.lang.InterruptedException ie ) {
                                                            System.err.println("Error sleeping: "+ie);
                                                    } // end catch
                                            } // end else
                                    } // end while
                                    is.close(); in.close();
                                    System.out.println("After while");
                                    System.exit(0);
                            } // end try
                            catch ( Exception e ) {
                                    System.err.println("Error reading lines: "+e);
                            } // end catch
                    } // end runThis seems to work on a few trial runs.. Does anyone see any possible random timing issues from this??

  • Oracle To End Support for Java 7

    No More Free Updates for Java 7 after April 2015
    Users must sign long-term support deals or migrate to Java 8 to avoid 'enormous headache and disruption to millions of applications'
    Public updates for Java 7 -- including bug and security fixes -- will end this month, a situation that one security advocate says could impact millions of applications.
    "As outlined in the Oracle JDK [Java Development Kit] Support Roadmap, after April 2015, Oracle will not post further updates of Java SE [Standard Edition] 7 to its public download sites," Oracle's Java SE Support Roadmap states. "Customers who need continued access to critical bug fixes and security fixes as well as general maintenance for Java SE 7 or older versions can get long-term support through Oracle Java SE Support. The process of migrating users from Java 7 to Java 8 through the auto update feature is expected to take place after the January 2015 CPU release."
    [ The art of programming is changing rapidly. We help you navigate what's hot in programming and what's going cold and give insights into the technologies that are changing how developers work. | Keep up with hot topics in app dev with InfoWorld's Application Development newsletter. ]
    Oracle released Java SE 7 in July 2011; Java SE 8 was released in March 2014. Java, particularly on the client side, has been beset by security issues in recent years. But Oracle has taken many steps to address the issues and stressed that most of the problems dated back several years, before Oracle took over Java from Sun in 2010.
    Still, the impact of Oracle's cessation of public updates could be severe, an official at security firm Waratek, believes. Oracle's "rapid" end-of-life schedule for Java versions is great for innovation and language evolution, Waratek CTO John Matthew Holt said in an emailed statement. "However, there is a dangerous tradeoff; now millions of Java 7 applications will have to defend themselves against code-level vulnerabilities without the benefit of future fixes." Holt advocates either upgrades to Java 8 or use of Java Run-time Application Self Protection (RASP) technologies (Waratek is a RASP vendor).
    This week's security update from Oracle, meanwhile, marks the "proverbial 'end of the road' for Java 7 application security, Holt said. "After today, the only version of the Java Platform which will receive public security updates is Java 8.  This is huge news, and it is going to cause enormous headache and disruption to millions of application owners around the world."
    Contacted Tuesday afternoon for a comment on the end of public updates for Java SE 7, by late evening Oracle had not yet responded.
    The April 2015 Critical Patch Update released Tuesday by Oracle provides 98 new fixes for security issues across a wide range of product families, said Eric Maurice in an Oracle blog post. These range from Oracle Database to Oracle Fusion Middleware, Java SE, and MySQL. Fourteen of the security fixes are for Java SE.

    Java 7 has already been dead for quite a while. While you could still use it for Java apps on your system, Apple blocked its use in browsers long ago. You have to install version 8 if you need Java support for the web.

  • 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

  • Obfuscators for Java

    Hello,
    I am looking for a free obfuscators for java.
    Any help is highly appreciable.
    Thanks

    We do obfuscate our code at my company, and
    I'm trying to think of another way to load files... I
    was thinking of encrypting the jar files and maybe
    using a class loader which would decrypt at run time
    to load the classes, but I think the entry point would
    still just be Java, and one could decrypt if knowing
    the key. Or by running your app in a Java debugger, setting a breakpoint at ClassLoader.defineClass, and looking at the decoded bytecode that's passed in as an attribute.
    No encryption mechanism that runs on, or in conjunction with, the ClassLoader interface in a standard Java virtual machine can prevent the bytecode being inspected.
    You have to write you own native methods to replicate the functionality of defineClass, without ever holding the clear form of your bytecode (as the native method could be inspected by a native debugger), which probably means writing your own native compiler.
    Pete

  • HTTP Web Proxy using Non Blocking IO

    Resolved Thanks................

    client.register(selector, SelectionKey.OP_READ
    | SelectionKey.OP_WRITE);OP_READ only at this stage. OP_WRITE is always 'ready' unless the socket send buffer is full, so your selector will just spin. Don't register OP_WRITE until you have something to write.
    ByteBuffer bferClient = ByteBuffer.allocate(4096);You're doing this every time around the loop, and you don't even know whether the key is readable yet. Do it when you accept a connection, and save it as the key attachment for that channel.
    client.configureBlocking(false);It's already in non-blocking mode. Why are you doing this again?
    try {
    if ((bytesRead = client.read(bferClient)) != -1) {
    bferClient.flip();
    String msgFromClient = new String(bferClient.array());new String(bferClient.array(), 0, bferClient.limit()-1), but you're assuming you got a complete command here. You may not have. That's another reason why you need a ByteBuffer per channel.
    channel.connect(socketAddress);You should do that in non-blocking mode, register the channel for OP_CONNECT, and let the select loop take care of finishing the connection.
    channel.write(bferClient);The incoming command was CONNECT. You don't write that upstream.
    if (!"".equals(msgFromClient.trim())) {
    int bytesReadServer;
    byte[] reply = new byte[4096];
    try {
    ByteBuffer bufferNIO = ByteBuffer.allocateDirect(1024);
    while ((channel.read(bufferNIO)) != -1) {
    bufferNIO.flip();
    client.write(bufferNIO);
    bufferNIO.clear();
    }And you don't do any of this here. You register the new channel for OP_CONNECT, then when you get that do finishConnect() and then register it for OP_READ, and proceed around your select loop. You also need to associate this channel with the channel you read the CONNECT from. So you really need a key attachment object for the original channel that contains its byte buffer and the upstream channel; similarly the upstream channel needs a key attachment that contains its buffer and its downstream channel. The effect of doing all this stuff here instead of around the select loop is that you are never getting back to the select loop: you are handling this one client here, in blocking mode, until the connection is dropped. Completely wrong.
    } catch (IOException e) {Hang on. If bytesRead was -1 you must close the channel.
    e.printStackTrace();And if you get any IOException here you must also close the channel.
    if (channel != null) {
    try {
    channel.close();This is a really strange place to close this channel.
    When you get all that fixed up, post your code and I'll tell you how to handle OP_WRITE.

  • Get IDE for Java?

    Where I can get a free IDE for Java which isn't written in Java or scripts (I have tried some written in Java, but they ate too much memory.)

    After reading your orginal question I did some more investigating on IDE for linux. In my previous experiance I haven't had much luck installing them, running them once installed, keeping them running once running. These seem to be the quality of Java IDEs written as freeware for Linux and not Java or Linux as a whole. After you asked your question I decided to give one more IDE a try. Jedit.
    http://www.jedit.org/
    The RPM installed right, the first time without intervention from me.
    It supports plug-ins.
    It does network installs of these plug-ins which was really cool and effortless
    It does all the things you asked for in your previous post
    It fails to meet one of your requirements... its written in java.
    however it is running on my linux box now, while I'm streaming mp3s and hosting a low volume web site, running Kde.
    My system is a AMD 950 with 256 meg RamRunning Redhat 7.2
    I haven't written much in the way of applications useing jEdit but it does look promissing.
    Ron_W

  • Writing Java Non-Blocking Socket Server for  Winsock Client

    Hi.
    Im a newbie to Sockets. I need to write a Non-Blocking Socket server (using java.nio) that accepts connection and reads the data sent by WinSock clients, and write them to another winsock client. Its quite intriguing. How do I do that? Is it possible?
    Thanks in advance
    Arun

    Well, in traditional 4.2 BSD sockets, you'd fill up a set of filedescriptors of connections (an array of bits usually), and push that in the read parameter of a call to 'select'. Select then blocks until at least one of the file descriptors become available for reading, or writing if you also made an fd_set full of file descriptors (but you can usually write freely to a socket, so there is not much use for that). Then you start finding out which of these file descriptors have actually become available for reading, and you pass those to a bunch of worker-threads. The advantage is that your set of worker-threads can be quite small, while your number of connections can still be quite large (unless, of course, everyone of your clients start talking all at once, but that is no different from the one-socket-one-thread-model that java.net.* forces upon you).
    In java, the 'select' call is replaced by a call to java.nio.channels.Selector.select(); and then the fishing out of the selected stuff comes from java.nio.channels.Selector.selectedKeys().
    To add a thingy to a selector, use (for example) java.nio.channel.ServerSocketChannel.register(Selector, ops, att);
    whereby the ops parameter is the kind of action you'd like to select this channel for; SelectionKey.OP_READ etc..
    The workerthread bit is also easy to write, but I leave that to you as an exercise.

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

  • Using non blocking connect() call for SCTP sockets in Solaris10

    Hi,
    I have a problem with non blocking connect call on SCTP socket.
    I am using the sctp stack support in Solaris10.
    When the connect is successful, I can get the pollout event on the socket.
    But there is no event observed when the peer does not exist. In other words, I could not get the pollout event on connection failure. This logic works fine with TCP sockets on both Solaris and Suse10.
    I am working with SCTP one-to-one style sockets.
    Is there any way to handle this issue?
    Do I need to load any patch to resolve this issue?
    It will be great if I get a solution in this regard.
    Thanks in advance.
    Best Regards,
    Bipin.

    There are at least two problems here.
    A. In the receiver you should test for -1 from the read() immediately, rather than continue with the loop and try to write -1 bytes to the file.
    B. In the sender you are ignoring the return value of client.write(), which can be anything from 0 to the buffer length. If you get 0 you should wait for another OP_WRITE to trigger; if you get a 'short write' you need to retry it until you've got nothing left to write from the current buffer, before you read any more data. This is where the data is vanishing.

  • Java.nio selector non-blocking IO question

    Hi,
    I am designing an interactive server where multiple clients can log on and communicate with the server. I designed a protocol that the client/server use to talk to each other. My server runs a Selector to monitor a ServerSocket, accepting connections and reading continuously from clients.
    Now my question is, since read() on ServerChannel are non-blocking using selector, how can I be sure that my entire protocol message will be read each time selector wakes up? For example, a slow client sends me a 5kb message, in one write() command, can I be sure that I will be able to read the entire message in one non-blocking read() command as well? If not, then the design becomes much more complicated, as I have to pipe each client's input into a handler thread that performs blocking i/o to read a protocol message one at a time. If I do that, then I might as well not use select() at all.
    I did some preliminary tests, and it seems that for my purpose (message of size <= 50kb), a read() command will always be able to read the entire message. But I can't find any documentation on this subject. My guess is that I cannot trust non-blocking I/O as well, which means it does not fit my purpose.
    Any help will be much appreciated.
    Thanks,
    Frank

    You can't be sure a read() will read in all the data from a client in one call.
    For example, say your message from the client to the server is of the following format. <start>message here<end>, where <start> indicates the start of a message and <end> the end of the message. In one read() call you might get "<start>message he". Your server would recognize this is partially correct but it needs the rest of the message. The server would store this and on the second read() you might get "re<end>" for the complete message.
    The purpose of non-blocking I/O is so you don't have to wait around for the second part of the message, you can process other client messages while the first client finishes sending their message. This way other clients aren't waiting around while you(the server) sit and wait for client 1 to finish sending it's data.
    So basically there is no gaurantee you will get a whole message intact. Your protocol will have to deal with partial messages, recognize them, store the partial message in a buffer, and on subsequent reads get the rest of the message.
    Nick

  • Free SMTP server for Java mail testing

    Hi all,
    Are there any free SMTP servers that can be downloaded from the Net for Java mail. Thanks.
    Regards
    Ram

    I am sorry ..may be my question was not very clear. I do not have am SMTP host. I need an SMTP host to route emails...is that possible.
    If I have an SMTP host on my machine, then it will act as a router to route messages to other email severs like yahoo or hotmail.
    So the "from" will be a user from the SMTP host.i.e my machine user and the "to" will be some email "[email protected]" or "[email protected]".
    Is it posssible to route emails directly to any Yahoo or hotmail server using just java mail client?
    Thanks
    Regards
    RP

  • Non-blocking file behaviour for Reader

    Hi!
    It will be really nice if Reader will not block files for writing. Assume someone is using TeX to create PDF and he need to
    a) examine the results;
    b) edit the source.
    It becomes a nightmare with Reader. Compile TeX, open Reader, examine results, close Reader. And then from the beginning.
    Auto reloading of a PDF file is also a nice feature!
    So far I can see only one solution: one should use another viewer to get non-blocking behaviour.
    Thanks!

    OK, let us see. I use Windows XP Professional SP3, Reader version is 9.3.0. I made a simple test: openned a file in Reader, then openned this file in my favourite text editor and tried to change "%PDF-1.4" to "%PDF-1.3" and save. I received a "File sharing violation error". I can also try to do it in Ubuntu.
    As for the open source viewers. That is what I am currently doing: I use additional viewer to view the files I create and I use Adobe Reader to view all other files. One can leave with such solution, but it is not the best.

  • RPC (non-xml based) for java

    We are looking at replacing and existing Proprietary (Distinct) RPC interface with a Sun RPC (non-xml based) version. I've seen mentioned somewhere about the sun.sunrpc.* package but can't find anything else about it.
    Something like rpcgen for java.
    Your help will be much appreciated.

    I think you mean RMI - Remote Method Invocation. No XML.

Maybe you are looking for

  • Getting bookmarks and address book to put into preference files in OS10 Jag

    hello I just loaded up OSX Jaguar on my computer I have a powermac G3 and originally have OS 9.2 classic also. I am trying to put my bookmarks and adbrees book in my browsers on OSX but cant find a place to put them both internet Explorer and Netscap

  • Ipad Video App don´t show 2 lines subtitles

    I´m using homesharing to stream the movies i have in my itunes computer. i have many video files in Full HD The problem only happen in the Ipad Video App, works fine in the Iphone Video App The problem only happen with video files that have height of

  • Conversion of source system after tranport

    Hi Im planning to to transport BI-Obejcts from DEV to QA . Where can i give 'conversion of sourcesystem after transport' and how can i give them. can i give in DEV or QA .please let me know kumar

  • Incompatibility of array with list

    I have three business classes. One is person which has attribute name of string type and a ArrayList of phone class. Phone class itself has one attribute of string type with name of "number". My third class is Patient which is inherited from Person c

  • Problem in starting up the database

    Hi, I have fixed the sysdate then changed it to fixed=none..and after that when we get down the database for backup it not getting up...we r using th pfile only and when i am trying wth startup pfile option it is showing like LRM-00101 - unknown para