如何在Grizzly中进行多线程处理

时间:2012-11-03 03:20:36

标签: java multithreading servlets heroku grizzly

我正在Heroku上实现Java RESTful Web服务。目前我的入口点似乎是

public class Main
{

    public static final String BASE_URI = getBaseURI();

    public static void main( String[] args ) throws Exception
    {
        final Map<String, String> initParams = new HashMap<String, String>();
        initParams.put( "com.sun.jersey.config.property.packages", "services.contracts" );
        initParams.put( "com.sun.jersey.api.json.POJOMappingFeature", "true" );

        System.out.println( "Starting grizzly..." );
        SelectorThread threadSelector =
        GrizzlyWebContainerFactory.create( BASE_URI, initParams );

        System.out.println( String.format( "Jersey started with WADL available at %sapplication.wadl.", BASE_URI,
                BASE_URI ) );
    }

    private static String getBaseURI()
    {
        return "http://localhost:" + ( System.getenv( "PORT" ) != null ? System.getenv( "PORT" ) : "9998" ) + "/";
    }

}

其中initParms包含托管的RESTful服务。我理解GrizzlyWebContainerFactory.create()返回ServletContainerSelectorThread)的实例,但我如何多线程返回的threadSelector,以便多个SelectorThread可以处理一个进程下的传入请求(又名web dyno)?原因是在处理请求时提高单个dyno的性能。

任何建议表示赞赏!谢谢!

1 个答案:

答案 0 :(得分:0)

您可以致电:

SelectorThread.setSelectorReadThreadsCount(int)