ASF Bugzilla – Attachment 36466 Details for
Bug 63210
Tomcat failing to shutdown if EvictionTimer thread is running
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Example servlet source to replicate the issue
TestServlet.java (text/plain), 2.64 KB, created by
kirk
on 2019-02-26 04:58:28 UTC
(
hide
)
Description:
Example servlet source to replicate the issue
Filename:
MIME Type:
Creator:
kirk
Created:
2019-02-26 04:58:28 UTC
Size:
2.64 KB
patch
obsolete
>package test; > >import java.io.IOException; >import java.io.PrintWriter; >import java.sql.Connection; >import java.sql.ResultSet; >import java.sql.SQLException; >import java.sql.Statement; >import java.util.ArrayList; >import java.util.List; > >import javax.naming.Context; >import javax.naming.InitialContext; >import javax.naming.NamingException; >import javax.servlet.ServletException; >import javax.servlet.http.HttpServlet; >import javax.servlet.http.HttpServletRequest; >import javax.servlet.http.HttpServletResponse; >import javax.sql.DataSource; > >public class TestServlet extends HttpServlet { > > private static final long serialVersionUID = 7133821315587941463L; > private DataSource DATASOURCE; > > @Override > public void init() throws ServletException { > Exception ex = new Exception(); > ex.printStackTrace(); > super.init(); > for (Data d : getEmployees()) { > System.out.println(d.empid + " -> " + d.name); > } > } > > private class Data { > public int empid; > public String name; > } > > private List<Data> getEmployees() { > List<Data> ret = new ArrayList<>(); > Connection con = null; > Statement stmt = null; > ResultSet rs = null; > try { > > DataSource ds = getDataSource(); > > con = ds.getConnection(); > stmt = con.createStatement(); > > rs = stmt.executeQuery("select empid, name from Employee"); > > while (rs.next()) { > Data d = new Data(); > d.empid = rs.getInt("empid"); > d.name = rs.getString("name"); > ret.add(d); > } > > } catch (SQLException e) { > e.printStackTrace(); > } finally { > try { > rs.close(); > stmt.close(); > con.close(); > } catch (SQLException e) { > System.out.println("Exception in closing DB resources"); > } > } > return ret; > } > > protected void doGet(HttpServletRequest request, HttpServletResponse response) > throws ServletException, IOException { > PrintWriter out = response.getWriter(); > response.setContentType("text/html"); > out.print("<html><body><h2>Employee Details</h2>"); > out.print("<table border=\"1\" cellspacing=10 cellpadding=5>"); > out.print("<th>Employee ID</th>"); > out.print("<th>Employee Name</th>"); > > for (Data d : getEmployees()) { > out.print("<tr>"); > out.print("<td>" + d.empid + "</td>"); > out.print("<td>" + d.name + "</td>"); > out.print("</tr>"); > } > out.print("</table></body><br/>"); > out.print("</html>"); > } > > private synchronized DataSource getDataSource() { > if (DATASOURCE == null) { > Context ctx = null; > try { > ctx = new InitialContext(); > DATASOURCE = (DataSource) ctx.lookup("java:/comp/env/jdbc/MyLocalDB"); > } catch (NamingException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > } > // TODO Auto-generated method stub > return DATASOURCE; > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 63210
:
36463
|
36464
|
36465
| 36466 |
36467
|
36468
|
36469