import com.sun.grizzly.http.embed.GrizzlyWebServer; import com.sun.grizzly.nio.transport.TCPNIOTransport; import com.sun.grizzly.tcp.http11.GrizzlyAdapter; import com.sun.grizzly.tcp.http11.GrizzlyRequest; import com.sun.grizzly.tcp.http11.GrizzlyResponse; import com.sun.grizzly.threadpool.DefaultThreadPool; import java.io.IOException; import java.sql.Timestamp; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class Main { public static void main(String[] args) throws IOException { final GrizzlyWebServer gws = new GrizzlyWebServer(4343); ((TCPNIOTransport) gws.getTransport()).setSelectorRunnersCount(10); gws.getTransport() .setInternalThreadPool(new DefaultThreadPool(10, 100, Integer.MAX_VALUE, 30, TimeUnit.SECONDS)); gws.getTransport().setWorkerThreadPool(new DefaultThreadPool(10, 200, Integer.MAX_VALUE, 30, TimeUnit.SECONDS)); gws.addGrizzlyAdapter(new GrizzlyAdapter() { private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); @Override public void service(final GrizzlyRequest request, final GrizzlyResponse response) { response.setContentType("text/plain"); response.suspend(); executor.scheduleAtFixedRate(new Runnable() { public void run() { try { if (response.isSuspended()) { response.getWriter().append(new Timestamp(System.currentTimeMillis()).toString()) .append("\n"); response.getWriter().flush(); } } catch (Exception e) { e.printStackTrace(); response.resume(); } } }, 1, 1, TimeUnit.SECONDS); } }, new String[]{"/qwe"}); gws.start(); } }