one of my pages sends 2 ajax requests to my servlet. These 2 requests are sent at the same time, and for some reason they finish nearly at the same time. This is odd b/c in theory the 2 requests know nothing about each other so one shouldn't influence the other, but over time i have seen a patte of them finishing at the same time, mostly.
The only thing i can think of is that SQL-Server is bottle-necking somewhere. Both requests query my Invoice table multiple times.
The first request "shares" a jdbc coection, it feels hacky. It makes multiple, small-ish queries to Invoice.
public Company calculateStatistics(int companyID){
Company company = new Company(companyID);
StringBuilder sql = new StringBuilder();
ResultSet rs;
sql.append("SELECT Address2, City, Region from Customers ");
sql.append("WHERE CustomerID = ? ");
try(Coection coection = CoectionManager.getCoection();
PreparedStatement statement = coection.prepareStatement(sql.toString())){
statement.setInt(1, companyID);
rs = statement.executeQuery();
while(rs.next()){
company.setStreetAddress(rs.getString("Address2"));
company.setCityState(rs.getString("City") + ", " + rs.getString("Region"));
}
company.setContacts(getCustomerContacts(companyID,coection));
Double totalSales = getLastYearTotalSales(companyID,coection);
if(totalSales != null){
company.setTotalSales(totalSales);
Double aviallTotalSales = getLastYearAviallSales(coection);
company.setPercentCorpSales((company.getTotalSales()/aviallTotalSales)*100);
setTopProductLine(company,coection);
company.setPercentCorpPLSales((company.getTopProductLineSales()/getLastYearAviallTopProductLine(coection))*100);
company.setLastOrderDate(getLastOrderDate(companyID,coection));
company.setAvgOrderValue(getAvgOrderValue(companyID,coection));
}
}
catch(Exception e){
e.printStackTrace();
}
retu company;
}
برچسب:
نویسنده: استخدام کار