2014-01-23 29 views
1

香港專業教育學院得到了下面的代碼作爲一種一個Hello World試驗的的Restlet像個單線程的Restlet服務器

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我想要多個線程?

回答

1

打開新的瀏覽器選項卡(或窗口)與打開新連接不同。瀏覽器真的很擅長重新使用已經打開的連接,20秒的延遲就是這方面的證據。您可以通過打印出服務器中的遠程IP +端口來驗證這一點,對於這兩個請求都是相同的。

在Firefox中,您可以通過按Ctrl + F5強制建立新的連接,Chrome可能具有類似的功能。但是您也可以編寫一個可以執行get-request的小型(多線程)客戶端程序:編寫起來並不困難,並且在您需要測試/調試服務器的其他功能時會派上用場。

+0

我結束了剛剛使用鉻和Safari瀏覽器 –