我正在使用java。我試圖執行一個線程,但是我得到的問題是 thread.start()
方法正在執行,但正如我們知道當我們調用線程的start
方法時,將在內部調用run()
方法。但在我的情況下,run()
方法沒有得到執行。執行run()方法時出現問題
我正在使用sellinium。有沒有機會因硒而得到這個問題?
// in some another class
公共靜態無效的主要(字串[] args)拋出異常{
parseArguments(args);
ScraperStore scraperStore = ScraperStore.getInstance();
SocialSiteManager siteManager = new SocialSiteManager();
sitesToScrape = siteManager.getSocialSitesToScrape();
for (SocialSite site : sitesToScrape) {
ScrapeThread srThread = new ScrapeThread("srThread");
Thread scraper = new Thread(srThread);
srThread.setSiteToScrape(site);
srThread.setPageTypeToScrape(startPageToScrape);
srThread.setTypeToScrape(typeToScrape);
ArrayList<String> listOfValues = ScraperStore.getNextUrlToScrape(startPageToScrape, site);
srThread.setTypeToScrape(typeToScrape);
try {
srThread.setUrlOwnedBy(listOfValues.get(0));
srThread.setStartUrl(listOfValues.get(1));
scraper.start();
boolean state=scraper.isAlive();
scrapeThreads.add(scraper);
}
catch (Exception e) {
e.printStackTrace();
}
//線程類
類ScrapeThread {
公共ScrapeThread(字符串threadName){
thread = new Thread(this,threadName);
System.out.println(thread.getName());
}
// run()的 公共無效的run(){
try {
System.out.println("in the run method");
selenium = new DefaultSelenium(config.getHost(), Integer.parseInt(config.getPort()), config
.getBrowser(), config.getUrl());
selenium.start();
Integer count = 0;
while (startUrl != null) {
HtmlPage homePage = new HtmlPage();
homePage.setCreatedBy(new String());
homePage.setCreatedon(new String());
homePage.setModifiedBy(new String());
homePage.setModifiedOn(new String());
homePage.setNoOfItemsFound(new String());
homePage.setOwnedBy(urlOwnedBy);
homePage.setPageType(scraper.getPageTypeToScrape());
homePage.setPageUrl(startUrl);
proxy = getInitialisedProxy();
scraper.setNavigator(proxy.getNavigator());
scraper.setStartUrl(startUrl);
try {
scraper.initialize();
} catch (MyException e) {
if(status==false){
throw new Exception(MyException.NOTFOUND);
}
}
不認爲硒會影響這一點。顯示一些代碼? – 2011-01-08 06:50:55
其實我的線程的run()方法有一些selenium代碼作爲selenium.start()所以最新情況是當我直接調用run()方法時,硒工作正常,但當我做正常的線程執行,即時通訊調用thread.start ()方法,然後硒是給問題。什麼可能是問題先生..? – saggy 2011-01-08 12:30:48
是ScrapeThread實現Runnable的嗎? – 2011-01-08 14:22:45