0

私はクエーサーが初めてで、これをやってみました。基本的に、ファイバーがスレッドをブロックしているという警告が表示されます。なんで ?以下のようなことはできませんか?

ありがとう

//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();
       }
4

1 に答える 1

0

docsの「暴走ファイバー」サブセクションをご覧ください。

HttpURLConnectionはスレッド ブロッキングであるため、ファイバー スケジューラから長時間にわたってスレッドを盗むのを避けるために (Quasar ベースのアプリケーションのパフォーマンスを損なうリスクがあります)、Quasar と統合された HTTP クライアントを使用する(または独自に統合する) 必要があります

于 2016-04-26T06:00:22.090 に答える