import java.io.File; import java.net.InetSocketAddress; import java.net.Socket; import java.nio.channels.AsynchronousChannelGroup; import java.nio.channels.AsynchronousServerSocketChannel; import java.nio.channels.AsynchronousSocketChannel; import java.nio.channels.CompletionHandler; import java.security.CodeSource; import java.security.Permission; import java.security.PermissionCollection; import java.security.Policy; import java.security.ProtectionDomain; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class NIOTest { public static void main(final String[] args) throws Exception { Policy.setPolicy(new Policy() { @Override public boolean implies(final ProtectionDomain domain, final Permission permission) { return true; } @Override public PermissionCollection getPermissions( final CodeSource codesource) { throw new Error(); } @Override public PermissionCollection getPermissions( final ProtectionDomain domain) { throw new Error(); } }); System.setSecurityManager(new SecurityManager()); ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(3); newFixedThreadPool.execute(new Runnable() { public void run() { new File("/tmp").exists(); System.out.println("ok"); } }); AsynchronousChannelGroup withThreadPool = AsynchronousChannelGroup .withThreadPool(newFixedThreadPool); AsynchronousServerSocketChannel open = AsynchronousServerSocketChannel .open(withThreadPool); open.bind(new InetSocketAddress(1111)); open.accept(null, new CompletionHandler() { public void completed( final AsynchronousSocketChannel result, final Void attachment) { try { new File("/tmp").exists(); } catch (Exception e) { System.out.println("ko"); e.printStackTrace(); } } public void failed(final Throwable exc, final Void attachment) { } }); new Socket("127.0.0.1", 1111).close(); open.close(); withThreadPool.shutdownNow(); } }