users@grizzly.java.net

Concurrent connections using Grizzly/Jersey

From: <bird_sky_at_hotmail.com>
Date: Thu, 20 Oct 2011 21:18:11 +0000 (GMT)

Hi,

We are embedding Grizzly in our code and are facing concurrent
connections in production. We are unable to scale beyond 7-8 concurrent
requests. I believe the problem lies in the way we are using Grizzly
and appreciate any help you can offer. I am able to replicate the
problem with the following sample code.

Please suggest what we are doing wrong and how can we use grizzly to
scale up to many more concurrent requests.

==========Main.java==========
import com.sun.grizzly.http.SelectorThread;
import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class Main {
    public static void main(String[] args) throws InterruptedException
{
        Map<String, String> initParams=new HashMap<String, String>();
        initParams.put("com.sun.jersey.config.property.packages",
"com.test");
        try {
            SelectorThread threadSelector =
GrizzlyWebContainerFactory.create("http://localhost:8080/",
initParams);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
========Default.java=========
package com.test;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("{path:.*}")
public class Default {
    @GET
    @Produces( "text/plain" )
    public String getMessage() {
        try {
            // Adding sleep to simulate some background processing
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "Hello World";
    }
}
=========================