<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: java NIO select() call does not block in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/java-nio-select-call-does-not-block/m-p/5256366#M659035</link>
    <description>Here is a sample of my Java NIO code using the select() statement. The select() does not block on HP-UX 11.11 as well as HP-UX 11.31 (with Java 1.6).&lt;BR /&gt;&lt;BR /&gt;import java.net.InetSocketAddress;&lt;BR /&gt;import java.nio.channels.SelectionKey;&lt;BR /&gt;import java.nio.channels.Selector;&lt;BR /&gt;import java.nio.channels.SocketChannel;&lt;BR /&gt;import java.nio.channels.spi.SelectorProvider;&lt;BR /&gt;import java.util.Iterator;&lt;BR /&gt;import java.util.Set;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;public class Test {&lt;BR /&gt;&lt;BR /&gt; /**&lt;BR /&gt;  * @param args&lt;BR /&gt;  */&lt;BR /&gt; public static void main(String[] args) {&lt;BR /&gt;  SocketChannel mxSocketChannel = null;&lt;BR /&gt;  Selector mxChannelsSelector = null;&lt;BR /&gt;  try&lt;BR /&gt;  {&lt;BR /&gt;   mxSocketChannel = SocketChannel.open();&lt;BR /&gt;   mxSocketChannel.configureBlocking(false);&lt;BR /&gt;   InetSocketAddress mxRemoteAddress = new InetSocketAddress("localhost", 51421);&lt;BR /&gt;   boolean t_connect = mxSocketChannel.connect(mxRemoteAddress);&lt;BR /&gt;   int mnInterestOps = SelectionKey.OP_CONNECT;&lt;BR /&gt;   //int mnInterestOps = SelectionKey.OP_CONNECT | SelectionKey.OP_READ;&lt;BR /&gt;&lt;BR /&gt;   //create the selector&lt;BR /&gt;   mxChannelsSelector= SelectorProvider.provider().openSelector();&lt;BR /&gt;&lt;BR /&gt;   //register the channel with the selector indicating an interest in &lt;BR /&gt;   // accepting new connections &lt;BR /&gt;   SelectionKey x_key = mxSocketChannel.register(mxChannelsSelector, mnInterestOps);&lt;BR /&gt;&lt;BR /&gt;   //select loop&lt;BR /&gt;   while(true)&lt;BR /&gt;   {&lt;BR /&gt;&lt;BR /&gt;    //block until connect response is received&lt;BR /&gt;    int selectReturn = mxChannelsSelector.select(0);&lt;BR /&gt;&lt;BR /&gt;    if (selectReturn == 0)&lt;BR /&gt;    {&lt;BR /&gt;     System.out.println("select returned 0");&lt;BR /&gt;    }&lt;BR /&gt;    &lt;BR /&gt;   } //end while(true)&lt;BR /&gt;&lt;BR /&gt;  } //end try block&lt;BR /&gt;  catch (Exception ex)&lt;BR /&gt;  {&lt;BR /&gt;   System.out.println("exception " + ex);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt; }&lt;BR /&gt;}</description>
    <pubDate>Wed, 29 Sep 2010 10:35:45 GMT</pubDate>
    <dc:creator>cthiebot</dc:creator>
    <dc:date>2010-09-29T10:35:45Z</dc:date>
    <item>
      <title>java NIO select() call does not block</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/java-nio-select-call-does-not-block/m-p/5256365#M659034</link>
      <description>On HP-UX 11.11, PA-RISC server, with Java JVM greater than 1.4.1, the Java NIO select() call does not block leading to 100% cpu utilization.&lt;BR /&gt;&lt;BR /&gt;I created a non-blocking SocketChannel and registered it with OP_CONNECT and OP_READ.&lt;BR /&gt;&lt;BR /&gt;The following select() returns 0 without ever blocking:&lt;BR /&gt;java.nio.channels.Selector mxChannelsSelector;&lt;BR /&gt;int selectReturn = mxChannelsSelector.select(lTimeout);&lt;BR /&gt;&lt;BR /&gt;The same code works with Java 1.4.1 on HP-UX 11.11. It works on Linux RedHat 5 + Java 1.6.&lt;BR /&gt;&lt;BR /&gt;How to make it work on HP-UX with the latest Java JVM (1.6)?&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Thu, 23 Sep 2010 07:27:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/java-nio-select-call-does-not-block/m-p/5256365#M659034</guid>
      <dc:creator>cthiebot</dc:creator>
      <dc:date>2010-09-23T07:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: java NIO select() call does not block</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/java-nio-select-call-does-not-block/m-p/5256366#M659035</link>
      <description>Here is a sample of my Java NIO code using the select() statement. The select() does not block on HP-UX 11.11 as well as HP-UX 11.31 (with Java 1.6).&lt;BR /&gt;&lt;BR /&gt;import java.net.InetSocketAddress;&lt;BR /&gt;import java.nio.channels.SelectionKey;&lt;BR /&gt;import java.nio.channels.Selector;&lt;BR /&gt;import java.nio.channels.SocketChannel;&lt;BR /&gt;import java.nio.channels.spi.SelectorProvider;&lt;BR /&gt;import java.util.Iterator;&lt;BR /&gt;import java.util.Set;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;public class Test {&lt;BR /&gt;&lt;BR /&gt; /**&lt;BR /&gt;  * @param args&lt;BR /&gt;  */&lt;BR /&gt; public static void main(String[] args) {&lt;BR /&gt;  SocketChannel mxSocketChannel = null;&lt;BR /&gt;  Selector mxChannelsSelector = null;&lt;BR /&gt;  try&lt;BR /&gt;  {&lt;BR /&gt;   mxSocketChannel = SocketChannel.open();&lt;BR /&gt;   mxSocketChannel.configureBlocking(false);&lt;BR /&gt;   InetSocketAddress mxRemoteAddress = new InetSocketAddress("localhost", 51421);&lt;BR /&gt;   boolean t_connect = mxSocketChannel.connect(mxRemoteAddress);&lt;BR /&gt;   int mnInterestOps = SelectionKey.OP_CONNECT;&lt;BR /&gt;   //int mnInterestOps = SelectionKey.OP_CONNECT | SelectionKey.OP_READ;&lt;BR /&gt;&lt;BR /&gt;   //create the selector&lt;BR /&gt;   mxChannelsSelector= SelectorProvider.provider().openSelector();&lt;BR /&gt;&lt;BR /&gt;   //register the channel with the selector indicating an interest in &lt;BR /&gt;   // accepting new connections &lt;BR /&gt;   SelectionKey x_key = mxSocketChannel.register(mxChannelsSelector, mnInterestOps);&lt;BR /&gt;&lt;BR /&gt;   //select loop&lt;BR /&gt;   while(true)&lt;BR /&gt;   {&lt;BR /&gt;&lt;BR /&gt;    //block until connect response is received&lt;BR /&gt;    int selectReturn = mxChannelsSelector.select(0);&lt;BR /&gt;&lt;BR /&gt;    if (selectReturn == 0)&lt;BR /&gt;    {&lt;BR /&gt;     System.out.println("select returned 0");&lt;BR /&gt;    }&lt;BR /&gt;    &lt;BR /&gt;   } //end while(true)&lt;BR /&gt;&lt;BR /&gt;  } //end try block&lt;BR /&gt;  catch (Exception ex)&lt;BR /&gt;  {&lt;BR /&gt;   System.out.println("exception " + ex);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt; }&lt;BR /&gt;}</description>
      <pubDate>Wed, 29 Sep 2010 10:35:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/java-nio-select-call-does-not-block/m-p/5256366#M659035</guid>
      <dc:creator>cthiebot</dc:creator>
      <dc:date>2010-09-29T10:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: java NIO select() call does not block</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/java-nio-select-call-does-not-block/m-p/5256367#M659036</link>
      <description>If nobody else has an answer here, you should contact the Response Center for java support.&lt;BR /&gt;&lt;BR /&gt;You could also use tusc to see what system calls are being made.</description>
      <pubDate>Thu, 30 Sep 2010 05:16:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/java-nio-select-call-does-not-block/m-p/5256367#M659036</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-09-30T05:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: java NIO select() call does not block</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/java-nio-select-call-does-not-block/m-p/5256368#M659037</link>
      <description>Actually, I noticed that the channel was already connected just after the connect() call. By testing the connect() return status and not setting the OP_CONNECT flag is the connection was  already established, the select() call was behaving properly. &lt;BR /&gt;&lt;BR /&gt;Here is the woking code sample:&lt;BR /&gt;&lt;BR /&gt;public static void main(String[] args) {&lt;BR /&gt;  SocketChannel mxSocketChannel = null;&lt;BR /&gt;  Selector mxChannelsSelector = null;&lt;BR /&gt;  int mnInterestOps = 0;&lt;BR /&gt;  try&lt;BR /&gt;  {&lt;BR /&gt;   mxSocketChannel = SocketChannel.open();&lt;BR /&gt;   mxSocketChannel.configureBlocking(false);&lt;BR /&gt;   InetSocketAddress mxRemoteAddress = new InetSocketAddress("localhost", 51421);&lt;BR /&gt;   boolean t_connect = mxSocketChannel.connect(mxRemoteAddress);&lt;BR /&gt;   &lt;BR /&gt;   if (t_connect)&lt;BR /&gt;   {&lt;BR /&gt;    System.out.println("connected");&lt;BR /&gt;      mnInterestOps = SelectionKey.OP_WRITE | SelectionKey.OP_READ ;&lt;BR /&gt;   }&lt;BR /&gt;   else&lt;BR /&gt;   {&lt;BR /&gt;    mnInterestOps = SelectionKey.OP_CONNECT;&lt;BR /&gt;   }&lt;BR /&gt;   &lt;BR /&gt;   &lt;BR /&gt;   //create the selector&lt;BR /&gt;   mxChannelsSelector= SelectorProvider.provider().openSelector();&lt;BR /&gt;&lt;BR /&gt;   //register the channel with the selector indicating an interest &lt;BR /&gt;   SelectionKey x_key = mxSocketChannel.register(mxChannelsSelector, mnInterestOps);&lt;BR /&gt;&lt;BR /&gt;     &lt;BR /&gt;   //select loop&lt;BR /&gt;   while(true)&lt;BR /&gt;   {&lt;BR /&gt;&lt;BR /&gt;    //block until connect response is received&lt;BR /&gt;    int selectReturn = mxChannelsSelector.select(0);&lt;BR /&gt;&lt;BR /&gt;    if (selectReturn == 0)&lt;BR /&gt;    {&lt;BR /&gt;     System.out.println("select returned 0");&lt;BR /&gt;         }&lt;BR /&gt;&lt;BR /&gt;    Set myKeys = mxChannelsSelector.selectedKeys();&lt;BR /&gt;&lt;BR /&gt;    if (!myKeys.isEmpty())&lt;BR /&gt;    {&lt;BR /&gt;     Iterator x_readyKeysIterator = myKeys.iterator();&lt;BR /&gt;     // Iterate over the set of keys for which events are available&lt;BR /&gt;     while (x_readyKeysIterator.hasNext())&lt;BR /&gt;     {&lt;BR /&gt;      SelectionKey x_selectionKey = (SelectionKey) x_readyKeysIterator.next();&lt;BR /&gt;&lt;BR /&gt;      // Remove selected key&lt;BR /&gt;      x_readyKeysIterator.remove();&lt;BR /&gt;&lt;BR /&gt;      if (x_selectionKey.isValid())&lt;BR /&gt;      {&lt;BR /&gt;       if (x_selectionKey.isConnectable()) {&lt;BR /&gt;        mxSocketChannel.finishConnect();&lt;BR /&gt;        System.out.println("connection 2 accepted");&lt;BR /&gt;&lt;BR /&gt;             }&lt;BR /&gt;       else if (x_selectionKey.isWritable()) {&lt;BR /&gt;        System.out.println("writable channel, select return =" + selectReturn);&lt;BR /&gt;             x_selectionKey.cancel();&lt;BR /&gt;        &lt;BR /&gt;       }&lt;BR /&gt;       else if (x_selectionKey.isReadable()) {&lt;BR /&gt;        System.out.println("readable channel" + selectReturn);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;       }&lt;BR /&gt;      }&lt;BR /&gt;      else&lt;BR /&gt;      {&lt;BR /&gt;       //cancel the channel registration with this selector&lt;BR /&gt;       x_selectionKey.cancel();&lt;BR /&gt;       System.out.println("key not valid");&lt;BR /&gt;      }&lt;BR /&gt;&lt;BR /&gt;     }&lt;BR /&gt;    }&lt;BR /&gt;   } //end while(true)&lt;BR /&gt;&lt;BR /&gt;  } //end try block&lt;BR /&gt;  catch (Exception ex)&lt;BR /&gt;  {&lt;BR /&gt;   System.out.println("exception " + ex);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Mon, 04 Oct 2010 10:46:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/java-nio-select-call-does-not-block/m-p/5256368#M659037</guid>
      <dc:creator>cthiebot</dc:creator>
      <dc:date>2010-10-04T10:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: java NIO select() call does not block</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/java-nio-select-call-does-not-block/m-p/5256369#M659038</link>
      <description>See my reply above.&lt;BR /&gt;Chris</description>
      <pubDate>Mon, 04 Oct 2010 10:48:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/java-nio-select-call-does-not-block/m-p/5256369#M659038</guid>
      <dc:creator>cthiebot</dc:creator>
      <dc:date>2010-10-04T10:48:02Z</dc:date>
    </item>
  </channel>
</rss>

