Thread.sleep (2000); } else { System.out.println (”Incoming connection

Call finishConnect() to complete the connection process. This method can be called safely at any time. One of the following will happen when invoking finishConnect() on a SocketChannel object in nonblocking mode: The connect() method has not yet been called. A NoConnectionPendingException is thrown. Connection establishment is underway but not yet complete. Nothing happens, and finishConnect() immediately returns false. The SocketChannel has been switched back to blocking mode since calling connect() in nonblocking mode. If necessary, the invoking thread blocks until connection establishment is complete. finishConnect() then returns true. Connection establishment has completed since the initial invocation of connect() or the last call to finishConnect(). Internal state is updated in the SocketChannel object to complete the transition to connected state, and finishConnect() returns true. The SocketChannel object can then be used to transfer data. The connection is already established. Nothing happens, and finishConnect() returns true. While in this intermediate connection-pending state, you should invoke only finishConnect(), isConnectPending(), or isConnected() on the channel. Once connection establishment has been successfully completed, isConnected() returns true. InetSocketAddress addr = new InetSocketAddress (host, port); SocketChannel sc = SocketChannel.open(); sc.configureBlocking (false); sc.connect (addr); while ( ! sc.finishConnect()) { doSomethingElse(); } doSomethingWithChannel (sc); sc.close(); Example 3-8 illustrates runnable code that manages an asynchronous connection. Example 3-8. Concurrent-connection establishment package com.ronsoft.books.nio.channels; import java.nio.channels.SocketChannel; import java.net.InetSocketAddress; /** * Demonstrate asynchronous connection of a SocketChannel. * @author Ron Hitchens (ron@ronsoft.com) */ public class ConnectAsync{ 109
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services

Comments are closed.