Пример




public class BpAllBadThingsServletsV1a extends HttpServlet {
private int numberOfRows = 0;
private javax.sql.DataSource ds = null;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection conn = null;
RersultSer rs = null;
PreparedStatement pStmt = null;
int startingRows;

try {
synchronized (this) { //блокирует большую часть обработки сервлета
startingRows = numberOfRows;
String employeeInformation = null;
conn = ds.getConnection("db2admin", "db2admin");
pStmt = conn.prepareStatement ("select * from db2admin.employee");
rs = pstmt.executeQuery();

//...

Исправление
Не блокируйте путь главного кода сервлета. Держите его за пределами синхронизируемого блока.

public class BpAllBadThingsServletsV1a extends HttpServlet {
private int numberOfRows = 0;
private javax.sql.DataSource ds = null;
private Object lockObject = new Object();
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection conn = null;
RersultSer rs = null;
PreparedStatement pStmt = null;
int startingRows;
synchronize(lockObject) {
startingRows = numberOfRows;
}
try {
String employeeInformation = null;
conn = ds.getConnection("db2admin", "db2admin");
pStmt = conn.prepareStatement ("select * from db2admin.employee");
rs = pstmt.executeQuery();

//...