mjs
mjs

Reputation: 22379

Thread safe and concurrent use, multiple instances?

Looking at com.ui4j.api.browser.BrowserFactory it appears as if the getBrowser method can only return one instance, as is also documented.

This is quite problematic for anyone trying to write some sort of multi threaded crawler, as there will only exists one browser at all times. There is no way to create a new tab on the browser, so you can only navigate one page at a time which is likely queued up in an list.

Do I really have to resort to having to copy and paste and rewrite the entire BrowserFactory class to get another instance, or is there a way to navigate multiple pages and parse out content concurrently?

Or is this a complete miss? As it stands now, the library is probably only suitable for test purposes. Threaded context is a neccessity in any production system.

Ofcourse I can copy and paste the code but is there another way?

Upvotes: 1

Views: 795

Answers (1)

user452425
user452425

Reputation:

BrowserFactory creates a singleton instance of BrowserEngine. BrowserEngine could create more than one page/tab. If you are trying to crawl a site you should review this example. The example create a thread pool with pool size 2. This means that browser could run 2 pages together.

Upvotes: 2

Related Questions