Skip to content

Profiler Example : loop.jsp file that reads each line from a file and prints the output.

The loop.jsp is a simple script that reads every line from an existing file and prints out the result.


<%@page import=""%>
<%@page import=""%>
<%@page import=""%>
<%@page import=""%>
<%@page import=""%>
<%@page import=""%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Read From a Text</title>
String jspPath = "/opt/applicationservers/tomcat/apache-tomcat-9.0.0.M4/webapps/JTA/controls/";
String fileName = "myFile.txt";
String txtFilePath = jspPath + fileName;
BufferedReader reader = new BufferedReader(new FileReader(txtFilePath));
StringBuilder sb = new StringBuilder();
String line;
for(int i=0;i<1000;i++)

    for(int j=0;j<i;j++)

    while((line = reader.readLine())!= null)

Profiler Results Page

When the execution of the script has finished, go to the Profiled Thread History tab and see the transaction details. ( See screenshot below )

Lets take a better look of the transaction. ( See screenshot below )

If we take a look in the Transaction details, we will be able to see that the most consuming method is the with 70.3% of the total execution time. Therefore, we can assume that reading a number of lines from a file inside a double for loop is not a good programming practice. The rest of the execution time was consumed from printing the lines of the file in the browser, and that method only consumed the 29.7% of the total time.