2012-11-03 25 views
0

我在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)下處理傳入請求?原因是在處理請求時提高單個測功機的性能。

任何建議表示讚賞!謝謝!

回答

0

您可以撥打:

SelectorThread.setSelectorReadThreadsCount(int)