What is the use of the inheritedChannel () method in the System class

This method was found in the System class. It’s just interesting to know about it -

public static Channel inheritedChannel() throws IOException { return SelectorProvider.provider().inheritedChannel(); } 

Description of Java Doc:

Returns the channel inherited from the object that created this Java virtual machine. This method returns the channel obtained by calling the system-wide default inheritedChannel method of the SelectorProvider object.

+7
source share
2 answers

It is designed to run Java programs on demand from inetd or xinetd on Unixy systems. Oracle has a few more documents and sample code, unfortunately related to RMI, in their Designing Services, which will be launched from inetd , and theres a very simple example in the Jetty source for InheritedChannelConnector and some interesting discussions in the JETTY-496 error, where Jetty feature has been introduced.

+8
source

From SelectorProvider.inheritedChannel () :

Returns the channel inherited from the object that this Java Virtual Machine created.

In many operating systems, a process, such as a virtual Java machine, can be started so that the process inherits a pipe from the object that created the process. the way this is done depends on the system, as well as the possible objects to which the channel can be connected. For example, on UNIX systems, the Internet services daemon ( inetd ) is used to run request servicing programs when a request arrives at a connected network port. In this example, the process that starts inherits the channel representing the network socket.

In cases where the legacy channel is a network socket, then the java.nio.channels.Channel type is returned by this method is determined as follows:

  • If the legacy channel represents a stream oriented socket connection, then java.nio.channels.SocketChannel is back. The socket channel, at least initially, blocks the mode associated with the socket address and associated with the peer.

  • If the legacy channel is a stream oriented socket listening, then java.nio.channels.ServerSocketChannel is returned. The server-socket channel is at least in blocking mode and tied to the socket address.

  • If the legacy channel is a datatron oriented socket then java.nio.channels.DatagramChannel is back. The datagram channel, at least initially, is blocked by the mode and bound to the socket address.

In addition to the described network channels, this method may return other types of channels in the future.

The first call to this method creates a channel that has returned. Subsequent calls to this method return the same channel.

+4
source

All Articles