If we are talking about standard sockets, then Socket.setSocketImplFactory(SocketImplFactory) used to change the factory for regular sockets and ServerSocket.setSocketFactory(SocketImplFactory) for server sockets.
If you use them, then pay attention to the fact that you can install these factories only once.
Note that the default java socket implementation uses SocksSocketImpl (the package visibility class in java.net) if it detects that the factory is null if you want the factory to be able to switch the package to standard java.
Nuoji source share