0
私は将来のマルチスレッドを使用したいと思いますが、私はexecutor.submit(呼び出し可能)を呼び出すと「未来から未来に変換できません」というエラーがあります。Javaの将来のマルチスレッド
package metier;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.sun.corba.se.impl.orbutil.closure.Future;
public class ScraperPages {
private String search;
private String location;
private List<Resultat> resultats;
private List<String> urls;
public ScraperPages(String search, String location) {
this.search = search;
this.location = location;
this.resultats = new ArrayList<Resultat>();
}
public void getUrls() {
String urlForPage = "https://www.pagesjaunes.fr/recherche/" + this.location + "/" + this.search;
String urlForInfos = "https://www.pagesjaunes.fr/annuaire/chercherlespros?quoiqui=" + this.search + "&ou="
+ this.location + "&page=";
urls = new ArrayList<String>();
try {
Document doc = Jsoup.connect(urlForPage).userAgent("Mozilla").ignoreHttpErrors(true).timeout(10000).get();
Elements divResult = doc.getElementsByClass("pagination-compteur");
int index = divResult.text().indexOf("/");
int nbPage = Integer.parseInt(divResult.text().substring(index + 2));
for (int i = 1; i < nbPage + 1; i++) {
urls.add(urlForInfos + i);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void ScrapUrls() throws InterruptedException {
Iterator<String> urlsIterator = urls.iterator();
ExecutorService executor = Executors.newFixedThreadPool(10);
Map<Future, String> tasks = new LinkedHashMap<Future, String>();
while (urlsIterator.hasNext()) {
String urlstr = urlsIterator.next();
Callable<Resultat> callable = new Callable<Resultat>() {
public Resultat call() throws Exception {
return scrapeIndividualURL(urlstr);
}
};
Future future = executor.submit(callable);
tasks.put(future, urlstr);
}
tasks.forEach((future, url) -> {
String content = future.toString();
});
executor.shutdown();
}
public static Resultat scrapeIndividualURL(String urlstr) {
Resultat result = null;
try {
Document doc = Jsoup.connect(urlstr).userAgent("Mozilla").ignoreHttpErrors(true).timeout(10000).get();
Elements divResult = doc.getElementsByClass("zone-bi");
for (Element e : divResult) {
if (e.getElementsByClass("denomination-links").size() != 0) {
String nom = e.getElementsByClass("denomination-links").get(0).text();
String adresse = e.getElementsByClass("adresse-container").get(0).getElementsByClass("adresse")
.text();
Elements mainContactDiv = e.getElementsByClass("main-contact-container");
String phone = "";
String cellphone = "";
for (Element el : mainContactDiv) {
if (el.getElementsByClass("tel-zone").size() != 0) {
Elements telZoneDiv = el.getElementsByClass("tel-zone");
for (Element ele : telZoneDiv) {
Elements test = ele.children();
for (int j = 0; j < test.size(); j++) {
if (j != 0) {
if (test.get(j - 1).text().equals(" Tél :")) {
phone = test.get(j).attr("title").toString();
}
if (test.get(j - 1).text().equals(" Mobile :")) {
cellphone = test.get(j).attr("title").toString();
}
}
}
}
}
}
result =new Resultat(nom,adresse,phone,cellphone);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
/**
* @return the search
*/
public String getSearch() {
return search;
}
/**
* @param search the search to set
*/
public void setSearch(String search) {
this.search = search;
}
/**
* @return the location
*/
public String getLocation() {
return location;
}
/**
* @param location the location to set
*/
public void setLocation(String location) {
this.location = location;
}
/**
* @return the resultats
*/
public List<Resultat> getResultats() {
return resultats;
}
/**
* @param resultats the resultats to set
*/
public void setResultats(List<Resultat> resultats) {
this.resultats = resultats;
}
/**
* @param urls the urls to set
*/
public void setUrls(List<String> urls) {
this.urls = urls;
}
}
私は私が間違ってやっているのか理解していません。私たちを手伝ってくれますか?
'輸入com.sun.corba.se.impl.orbutil.closure.Futureで
を交換してください;' - 私は思う間違った未来を。 –
私はジョーが正しいと思う。 IDEがあなたのために選んだインポートを見てください。同じ名前のクラスが2つ以上ある場合は、代わりに奇妙なクラスを選択することがあります。 – Carcigenicate
ああそうだよ!あまりにも愚か。ご不便おかけしてすみません。 – Erylis