【问题标题】:Quasar multi fibers warningQuasar 多光纤警告
【发布时间】:2016-04-25 15:33:32
【问题描述】:

我是 quasar 的新手,我尝试过这样做。 基本上我收到一个警告,光纤阻塞了一个线程。为什么 ?我可以不做下面这样的事情吗?

谢谢

//in my my testclass I have this
String websites[] = {"http://www.google.com",""http://www.lol.com",""http://www.somenoneexistantwebsite.com"};
            for(int i=0; i < websites.length ; i++){
            TestApp.getWebsiteHTML(websites[i]); 
            }


//in TestApp

     public static void getWebsiteHTML(String webURL) throws IOException, InterruptedException, Exception {
            new Fiber<Void>(new SuspendableRunnable() {
                @Override
                public void run() throws SuspendExecution, InterruptedException {
                WebInfo mywi = new WebInfo();
                mywi.getHTML(webURL);
                }
            }).start().join();
        }        

//in WebInfo
      public static String getHTML(String urlToRead) throws Exception {
          StringBuilder result = new StringBuilder();
          URL url = new URL(urlToRead);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          conn.setRequestMethod("GET");
          BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
          String line;
          while ((line = rd.readLine()) != null) {
             result.append(line);
          }
          rd.close();
          return result.toString();
       }

【问题讨论】:

    标签: quasar


    【解决方案1】:

    查看docs 中的“失控纤维”小节。

    HttpURLConnection 是线程阻塞的,所以为了避免从光纤调度器中窃取线程太长时间(这可能会破坏基于 Quasar 的应用程序的性能),您应该使用HTTP client integrated with Quasar(或integrate one yourself) .

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-09
      • 2020-01-08
      • 2018-10-10
      • 2017-11-30
      • 2013-12-05
      • 1970-01-01
      • 2013-12-05
      相关资源
      最近更新 更多