2011-10-04 28 views
0

我是Restlet框架的新手,我的服務器資源的post方法中有以下時間問題。 我的方法後代碼Restlet中的表單實例化時間

@Post 
    public Representation represent(Representation entity){ 
     try{ 
      //Thread.sleep(1000); 
      long start = System.currentTimeMillis(); 
      Form aForm = new Form(getRequestEntity()); 
      System.err.println("FORM Instantiation TIME: " + (System.currentTimeMillis()-start)); 
     }catch(Exception ex){ 
      ex.printStackTrace(); 
     } 
     return new StringRepresentation("hello"); 
    } 

在不同的路徑,那我得到的是1900-1999毫秒的輸出。但是如果我取消註釋Thread.sleep(1000)這一行,那麼時間輸出是900-999毫秒。任何人都可以確認實例化Form對象時發生了什麼,以及爲什麼時間始終爲1900+ ms。整理這個時間問題對我來說很重要,因爲我必須實施基於令牌的認證,以減少post方法的處理時間。

+0

您能否提供詳細信息,例如所使用的Restlet的版本,所涉及的HTTP連接器以及特別是客戶端詳細信息。這是一個本地測試,等等。 –

回答

0

對不起,延遲迴復。我使用該版本的Restlet 2.0.7是這裏 是細節

public static void main(String[] args) throws Exception { 
     Component component = new Component(); 
     component.getServers().add(Protocol.HTTP, 8182); 
     VirtualHost aHost = component.getDefaultHost(); 
     aHost.attach("/sample", new MyApplication()); 
     component.getLogger().setLevel(Level.OFF); 
     component.start(); 
     System.err.println("REST SERVICE STARTED ON PORT NUMBER 8182..."); 
    } 

我運行在本地這個應用程序,而不是在任何Web /應用服務器。