Menu

#1704 Threaded webClient slowly increase CPU usage to 100%....

Latest SVN
open
nobody
CPU (1) 100% (1)
9
2015-08-05
2015-07-29
Kliton Bare
No

Hi,
i'm using HtmlUnit in a java client to interact with a site.
I need to keep opened the page always opened, so i have created a thread with a while(true) when every 15 minutes i refresh the HtmlPage with this code:

if (totSleep >= 830){
    this.totSleep = 0;
        try {
                this.page.getWebResponse().getWebRequest().getUrl();
                 Thread.sleep(10000);
            } 
        catch (Exception e) {
                this.lastError = 1;
           }
}

I start the webClient and get the page inside the Thread with this code:

                        try {
                                webClient = new WebClient(BrowserVersion.CHROME);      
                                webClient
                                .setAjaxController(new NicelyResynchronizingAjaxController());
                                webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
                                webClient.getOptions().setThrowExceptionOnScriptError(false);
                                webClient.getOptions().setRedirectEnabled(false);
                                webClient.getOptions().setTimeout(30000);
                                webClient.getOptions().setCssEnabled(false);
                                webClient.getOptions().setAppletEnabled(false);
                                //webClient.setJavaScriptTimeout(30000);
                                page = webClient.getPage("hidden");
                                //webClient.waitForBackgroundJavaScript(10000);
                                Thread.sleep(10000);


                        this.lastError = 0;
                        } catch (Exception e) {
                                // TODO Auto-generated catch block

                                e.printStackTrace();
                                this.isLogged = false;
                                this.lastError = 1; 
                                 continue;
                        }
                }                       

When i close the webClient ( after a lot of hours, in many cases after a lot of days ) i use this code ( which is outside the thread )

try{
webClient.close();
page = null;
webClient.closeAllWindows();
}catch(Exception e1){
System.out.println("Ecc durante la puli!");
}

This thread is a class that Implements Runnable, so my custom class contain a Run() method, in this run method i have put a while(true) which contain all the code posted above....

Why, when i have the thread started the cpu is going in a few hours to 100%?

Ps. the site that i'm loading contain javascript code, so i need that enabled ;)
The site is this: https://trade.optionsclick.com/

Best regards,
Kliton

Discussion

  • Kliton Bare

    Kliton Bare - 2015-08-01

    Nothing?

     
  • RBRi

    RBRi - 2015-08-01

    Do you use the latest snapshot?

     
  • Kliton Bare

    Kliton Bare - 2015-08-01

    I think so.

    <dependency>
    <groupid>net.sourceforge.htmlunit</groupid>
    <artifactid>htmlunit</artifactid>
    <version>2.18</version>
    </dependency>

    Is the 2.18 the latest SVN?

     
  • RBRi

    RBRi - 2015-08-01

    Not really, but there is no difference regarding memory issues.

     
  • RBRi

    RBRi - 2015-08-01

    Can you pls attach the whole code.
    And why you think this.page.getWebResponse().getWebRequest().getUrl(); refreshes your page.

     

    Last edit: RBRi 2015-08-01
  • Kliton Bare

    Kliton Bare - 2015-08-01

    Ok, i have attached the OptionsClick.java file ;)

    I think that this.page.getWebResponse().getWebRequest().getUrl() refresh the page because i have read that on internet, am i wrong?

    Is there the memory error?

    Thank you

     
  • RBRi

    RBRi - 2015-08-01

    will have a look during the next days

     
  • Kliton Bare

    Kliton Bare - 2015-08-01

    Ok thank you ;)

     
  • Kliton Bare

    Kliton Bare - 2015-08-05

    Hi, any update please?

     

Log in to post a comment.