2012-02-15 17 views
1

restlet 2.0.11を使用してサーバーを実行しようとしていますが、スレッドが多すぎるためにサーバーが諦めています。 例を挙げて私のサーバーのスレッド数を増やすのに誰かが助けてくれますか?Restlet 2.0.11スレッド数を増やす

try 
{ 
    Server server = new Server(Protocol.HTTP, m_iPort, ContentProvider.class); 
    server.start(); 
} 
catch (Exception e) 
{ 
    e.printStackTrace(); 
} 

私はサンプルを探しているが、

getContext().getParameters().add("maxThreads", "512"); 

は私にnullポインタ例外を与えます。

+0

getContext()。getParameters()。add( "maxThreads"、 "512");のいずれの部分がnullですか?各部分をローカル変数に抽出し、nullをチェックします。 –

+0

これは機能します。 org.restlet.Contextをインポートする必要がありました。 – user1152640

+0

実際には、もう少し調査した後、getContext()はnullを返します。 – user1152640

答えて

0

org.restlet.Serverのインスタンスを作成するときに返されるorg.restlet.Serverのインスタンスを取得した後、コンテキストを取得し、整数と新しいプロパティmaxThreadsの、次のように:

import org.restlet.Component; 
import org.restlet.Server; 
//... 
Server server = mycomponent.getServers().add(Protocol.HTTP, "localhost", 9090); 
server.getContext().getParameters().add("maxThreads", "512"); 

それはあなたの間違いのようにあなたがコンポーネントのコンテキストプロパティ、またはJavaプログラム自体をつかんで、そして自然にそこにパラメータを割り当てていたに見え無視されます。

ここフラー例:

package carpool.serverMain; 

import java.util.ArrayList; 

import org.json.JSONObject; 
import org.restlet.Component; 
import org.restlet.Server; 
import org.restlet.data.Protocol; 

import carpool.common.DebugLog; 
import carpool.configurations.CarpoolConfig; 
import carpool.configurations.EnumConfig.Gender; 
import carpool.dbservice.LocationDaoService; 
import carpool.factory.JSONFactory; 
import carpool.service.*; 



public class ServerMain { 

//private static Log log = LogFactory.getLog(ServiceMain.class); 

private static ServerMain me; 

private Component component; 

public void init(String[] arguments) { 

} 

/** 
    * Start the Thread, accept incoming connections 
    * 
    * Use this entry point to start with embedded HTTP Server 
    * 
    * @throws Exception 
    */ 
public void start() throws Exception { 
    component = new Component(); 

    // Add a new HTTP server listening on port 

    Server server = component.getServers().add(Protocol.HTTP, 8015); 
    server.getContext().getParameters().add("maxThreads", "256"); 

    // Attach the sample application 
    RoutingService routingService = new RoutingService(); 

    component.getDefaultHost().attach(routingService); 

    // Start the component. 
    //log.info("ready to start"); 
    DebugLog.d("ready to start"); 
    component.start(); 

} 

/** 
    * Stops RESTlet application 
    */ 
// public void stop() { 
// component.getDefaultHost().detach(component.getApplication()); 
// } 

public static ServerMain getInstance() { 
    if (me == null) { 
    me = new ServerMain(); 
    } 

    return me; 
} 



public static void main(String... args) throws Exception { 
    CarpoolConfig.initConfig(); 
    DebugLog.initializeLogger(); 
    LocationDaoService.init(); 
    DebugLog.d("Excuting"); 
    // Load server logic 
    try { 
    ServerMain.getInstance().init(args); 
    ServerMain.getInstance().start(); 
    } catch (Exception e) { 
    //log.error("Failed to start server", e); 
    } 
    Thread thread = new CleanThreadService(); 
    thread.start(); 
} 

} 
1

エリックの答えはのRestlet 2.0.11のために、おそらく正しかったが、これ以降:

http://www.programcreek.com/java-api-examples/index.php?api=org.restlet.data.Protocol

場合リンクでプログラム全体がダウンRestlet maxThreadsのGoogleとの最初のマッチですが、私はアップデートを投稿するべきだと思っていました。

これは変更されたRestlet/Jettyのバージョンがわかりませんが、Restlet 2.3.7ではmaxThreadsとminThreadsの設定を無視しています。あなたは今、自分たちのライブラリをアップグレードするときに、ユーザーが経験するものにあるかどうかに関係なく、私の知る限り、これはおそらく、コードをクリーンアップするのが好き者による突堤プロジェクトで化粧リファクタリングです

server.getContext().getParameters().add("threadPool.maxThreads", "256"); 

を呼び出す必要があります。また、Jettyはあなたに無効なパラメータを警告するようなことはありません。黙って無視するだけです。これはまさに自由形式のString-Stringパラメータでは見たくないものです。