當前位置: 首頁>>代碼示例>>Java>>正文


Java Map.wait方法代碼示例

本文整理匯總了Java中java.util.Map.wait方法的典型用法代碼示例。如果您正苦於以下問題:Java Map.wait方法的具體用法?Java Map.wait怎麽用?Java Map.wait使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Map的用法示例。


在下文中一共展示了Map.wait方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: executeRequest

import java.util.Map; //導入方法依賴的package包/類
public static HttpResponse executeRequest(HttpRequest p_executeRequest_0_) throws IOException
{
    final Map<String, Object> map = new HashMap();
    String s = "Response";
    String s1 = "Exception";
    HttpListener httplistener = new HttpListener()
    {
        public void finished(HttpRequest p_finished_1_, HttpResponse p_finished_2_)
        {
            synchronized (map)
            {
                map.put("Response", p_finished_2_);
                map.notifyAll();
            }
        }
        public void failed(HttpRequest p_failed_1_, Exception p_failed_2_)
        {
            synchronized (map)
            {
                map.put("Exception", p_failed_2_);
                map.notifyAll();
            }
        }
    };

    synchronized (map)
    {
        HttpPipelineRequest httppipelinerequest = new HttpPipelineRequest(p_executeRequest_0_, httplistener);
        addRequest(httppipelinerequest);

        try
        {
            map.wait();
        }
        catch (InterruptedException var10)
        {
            throw new InterruptedIOException("Interrupted");
        }

        Exception exception = (Exception)map.get("Exception");

        if (exception != null)
        {
            if (exception instanceof IOException)
            {
                throw(IOException)exception;
            }
            else if (exception instanceof RuntimeException)
            {
                throw(RuntimeException)exception;
            }
            else
            {
                throw new RuntimeException(exception.getMessage(), exception);
            }
        }
        else
        {
            HttpResponse httpresponse = (HttpResponse)map.get("Response");

            if (httpresponse == null)
            {
                throw new IOException("Response is null");
            }
            else
            {
                return httpresponse;
            }
        }
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:72,代碼來源:HttpPipeline.java


注:本文中的java.util.Map.wait方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。