Ejemplo




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) { //bloquea la mayoría del proceso del servlet
startingRows = numberOfRows;
String employeeInformation = null;
conn = ds.getConnection("db2admin", "db2admin");
pStmt = conn.prepareStatement ("select * from db2admin.employee");
rs = pstmt.executeQuery();

//...

Solución
No bloquee la vía de acceso de código principal del Servlet. Muévala fuera de un bloque sincronizado.

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();

//...