1

当我尝试同时通过 100 个线程从我的 API 请求资源时(这是一个简单的性能测试),我收到以下服务器错误消息:

Unable to run the following server-side task: Handle inbound messages

我已经搜索了互联网,但找不到任何提示如何摆脱它。

任何经验如何处理该错误?

问候,厨师

编辑

客户:

public class PerformanceTest  extends Thread {
static ClientResource client;
static int recCounter = 0;
public PerformanceTest(){
    super();
}
public static void main(String[] args){
    client = new ClientResource("http://localhost:8082/api/module/news/1");
    ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC;
    ChallengeResponse authentication = new ChallengeResponse(scheme, "app+postapp", "");
    client.setChallengeResponse(authentication);    
    for(int i = 0; i < 100; i++){
        System.out.println("Starting test: " + i);
         new PerformanceTest().start();
    }
}

@Override
public void run() {
    JsonRepresentation entity;
    try {
        entity = new JsonRepresentation(client.get());
        recCounter++;
        System.out.println("(" + getRecCounter() + ") result: " + entity.getJsonObject().toString());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

private synchronized int getRecCounter(){
    return recCounter;
}

服务器: 这是我启动服务器的应用程序类:

public class MyApplication extends Application {
private DB db;

public MyApplication() {
    db = new DB();
}

public static void main(String[] args) throws Exception {
    Component component = new Component();
    component.getServers().add(Protocol.HTTP, 8082);
    Application application = new MyApplication();
    // Attach the application to the component with a defined contextroot
    String contextRoot = "/api";
    component.getDefaultHost().attach(contextRoot, application);
    component.start();
}

public Restlet createInboundRoot() {
    router.attach("/module/news", NewsResource.class);
    router.attach("/module/news/{itemId}", NewsResource.class);

    router.attach("/module/news/item", NewsResource.class);
    router.attach("/module/news/item/{itemId}", NewsResource.class);

    // Create Verifier
    CredentialsVerifier verifier = new CredentialsVerifier(getDB());

    // Create a Guard
    ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, "app");
    guard.setVerifier(verifier);

    guard.setNext(router);
    return guard;
}

public synchronized DB getDB() {
    return this.db;
}

}

4

0 回答 0