私は、URLから価格を取得し、それを整数に解析するために使用できる「パーサー」と呼ばれるクラスを持っています。URLをコンストラクタで同時に解析するには?
次に、これらの変数を使用してオブジェクトを作成する他のクラスがあります。問題は、連続して実行されているため、非常に遅いことです。
URLをパラレルに解析する方法を教えてください。
public class Parser {
public static int getPrice(String url) {
String price = "";
try {
Document doc = Jsoup.connect(url).get();
price = doc.select("h3").select("span").attr("title");
} catch (IOException e) {
e.printStackTrace();
}
return parseInt(price);
}
public static double parseDouble(String parseMe) {
NumberFormat ukFormat = NumberFormat.getNumberInstance(Locale.UK);
double parsed = 0;
try {
parsed = ukFormat.parse(parseMe).doubleValue();
} catch (ParseException e) {
e.printStackTrace();
}
return parsed;
}
}
//Here is an example of the class
public class Example(){
private int field1, field2;
public Example(String url1, String url2){
field1=Parser.getPrice(url1);
field2=Parser.getPrice(url2);
}
}