Java – a general way to optimize program speed
In terms of speed, what general methods can optimize programs in Java I use DOM parser to parse the XML file, then store some words in ArrayList, delete all duplicates, and then check the spelling of these words by creating a Google search URL for each word, get the HTML document, find the corrected words and save them to another ArrayList
Any help will be greatly appreciated! thank you.
Solution
Why improve performance? From your explanation, it is obvious that the major bottleneck (or performance loss) here will be IO caused by your access to the URL
This will certainly dwarf any minor improvements you make in data structures or XML frameworks
Your large performance problems will involve IO, which is a good general rule of thumb Very humorous. I'm waiting for the database query to return during batch processing It has been running for nearly an hour But I welcome any suggestions to improve my XML parsing library!
This is my general approach:
>Does your program perform any significantly expensive tasks from an IO perspective? You have enough logs to see that this is where the delay is (if important)? > Is your program prone to lock contention (that is, it can wait, do nothing, and wait for some resources to be "free")? Maybe you are locking the entire map, making expensive calculations on the stored values and preventing other threads from accessing the map > are there any obvious algorithms that may have poor characteristics (which may be used for data matching or sorting)? > Run an analyzer (such as jvisualvm, provided with the JDK itself) and view the code hotspots Where does the JVM spend time?