0

I show here a MCVE, which can be used to produce appearance of an additional javascript executor thread. You need a HtmlUnit dependency to run it, the maven coordinates for the latest snapshot are:

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.20-SNAPSHOT</version>
</dependency>

The MVCE listing:

import com.gargoylesoftware.htmlunit.WebClient;
public class SOQuestion34192800 {
    public static void main(String[] args) throws Exception {
        try (WebClient webClient = new WebClient()) {
            webClient.getOptions().setJavaScriptEnabled(false);
            webClient.getPage("http://stackoverflow.com");
            Thread.sleep(10000);
        }
    }
}

I start it in Eclipse and this is what I see in the debug view:

Eclipse Debug View

After I spent a lot of time to get rid of using javascript with HttpUnit in my application (because it is really slow), I expected it would reward me with a cleaner java process. But this thread still pops up and kinda bugs me. Is this a normal behavior, which can be justified, or just a bug?

Danny Lo
  • 1,553
  • 4
  • 26
  • 48

1 Answers1

0

You can put webClient.close() in the finally block.The JS executor thread will be finished and disappear.

try {
    // do some thing
}finally {
    webClient.close();
}
Green Lei
  • 3,150
  • 2
  • 20
  • 25
  • I think `webClient.close()` is automatically called when I leave the try-block. The focus of my question lies in that block. Again: I am just wondering why JS executor thread appears although I told `webClient` not to use JS (`setJavaScriptEnabled(false)`) – Danny Lo Dec 22 '15 at 03:05