In the previous section, we diagnosed different hot spot areas and classified them into different types (either the method's self-time or the invocation count is high, or both). Now let's describe some examples of the potential root causes of these hot spots.
When the application logic is generally the root cause of the performance issue, there can be many variants such as unnecessary loops, underperforming algorithms, repeated calculations, and no caching.
If we look at our online shopping project, ExampleTwo
, we see some samples of this ineffective application logic, shown as follows:
Product[] allProducts = catalogSessionBean.loadAllActiveProductCatalogByCriteria(new SearchCriteria()); for (Product allProduct : allProducts) { if(allProduct.getId()==productId){ outputStream.write(allProduct.getImage()); outputStream.close(); return; } }
In this logic, instead of getting the product by its ID, we get all the catalog...