Java Restlet服务器就像一个线程

Java Restlet服务器就像一个线程,java,multithreading,restlet,thread-sleep,Java,Multithreading,Restlet,Thread Sleep,我得到了以下代码作为restlet的hello world测试 public static void main(String[] args) throws Exception { //Find a way to get these from the ARGS... Settings.setCurrent(new Settings()); // Create a new Restlet component and add a HTTP server connector t

我得到了以下代码作为restlet的hello world测试

public static void main(String[] args) throws Exception {
    //Find a way to get these from the ARGS...
    Settings.setCurrent(new Settings());

    // Create a new Restlet component and add a HTTP server connector to it  

component.getServers().add(Protocol.HTTP, 8182);

    component.getContext().getParameters().add("maxThreads", "512");
component.getContext().getParameters().add("minThreads", "100");

component.getDefaultHost().attach("/findMissingPackages", Jeblet.class);

    // Now, let's start the component!  
// Note that the HTTP server connector is also automatically started.  
component.start();
}

@Get
public String toString() {
  try {
  Thread.sleep(10000);
  }
  catch(Exception ex) { }
  String settingString = "stuff";
  return settingString;
}
我遇到的问题是,如果我在chrome中打开两个选项卡,并连续两次访问服务器,则需要20秒才能在第二个选项卡上获得响应。这两个选项卡都需要10秒钟

调试时,我只有一个调度器。如何告诉restlet我想要多个线程?

打开新浏览器选项卡(或窗口)与打开新连接不同。浏览器真的很擅长重新使用已经打开的连接,20秒的延迟就是证明。您可以通过打印出服务器中的远程IP+端口来验证这一点,这两个请求都是相同的


在Firefox中,按ctrl+F5可以强制建立新连接,Chrome可能也有类似的功能。但您也可以编写一个小的(多线程)客户端程序来执行get请求:编写起来并不困难,当您需要测试/调试服务器的其他功能时,它会派上用场。

我最后只使用了chrome和safari