Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7631061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:15:27+00:00 2026-05-31T06:15:27+00:00

In my project, I need to download a html (about 50K-100K long when read

  • 0

In my project, I need to download a html (about 50K-100K long when read into String, yes, quite fat), and fetch some contents using regular expressions.And then insert them into the database.
The performance is quite bad, and I want to know why.

The process of the codes is like that (multithreaded):

  1. using httpcomponents to download the html file into String (String html)
  2. using Regular expressions to fetch the content,and insert (database is mysql)
Pattern p = Pattern.compile("<h.*</a></h.>",Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(html);
boolean result = m.find();
while (result) {
    //insert into database stuff
    //update database stuff
}

The string is very long, but if I split it into pieces, some matches may be missed. This is quite disturbing.

I added some print lines and find that after inserting into database, there are some delays, before updating operations, but I can’t figure it out as the connection to the database isn’t closed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:15:29+00:00Added an answer on May 31, 2026 at 6:15 am
    1. Try avoid Regex, use standard HTML Parser like JSoup, there are many. They might be more efficient, at least more than Regex, I would hope.

    2. If using regex, try not compiling regex each time. Can have a private static for the Pattern. But this ain’t huge gain in performance, just good practice.

    3. Use connection pooling for Database. If possible do batch inserts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im doing this project where i need to download files through a webservice (images,
I am working on a project in which I need to download and parse
my project need to read multiple web pages at a time(eg: for a particular
In my project i need to take an expression input from user as string
For one of my statistics project, I need to RANDOMLY download several files from
I need an advice for a project I am about to begin. In few
I am working on csv downloader project ,i need to download the CSV files
In my application I need to download pdf by parsing HTML on client side
In my project , i need to download the csv files in the webpage
My project need to compare output(only urls) of google and yahoo for a particular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.