You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/10/21 10:05:44 UTC

svn commit: r1709743 - in /tomcat/trunk/webapps/examples: WEB-INF/classes/async/Async0.java WEB-INF/classes/async/Async2.java jsp/async/async1.jsp jsp/async/async3.jsp

Author: markt
Date: Wed Oct 21 08:05:44 2015
New Revision: 1709743

URL: http://svn.apache.org/viewvc?rev=1709743&view=rev
Log:
Better time stamps for the async examples.

Modified:
    tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async0.java
    tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async2.java
    tomcat/trunk/webapps/examples/jsp/async/async1.jsp
    tomcat/trunk/webapps/examples/jsp/async/async3.jsp

Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async0.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async0.java?rev=1709743&r1=1709742&r2=1709743&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async0.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async0.java Wed Oct 21 08:05:44 2015
@@ -17,6 +17,8 @@
 package async;
 
 import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 import javax.servlet.AsyncContext;
 import javax.servlet.ServletException;
@@ -38,7 +40,9 @@ public class Async0 extends HttpServlet
         if (Boolean.TRUE == req.getAttribute("dispatch")) {
             log.info("Received dispatch, completing on the worker thread.");
             log.info("After complete called started:"+req.isAsyncStarted());
-            resp.getWriter().write("Async dispatch worked:+"+System.currentTimeMillis()+"\n");
+            Date date = new Date(System.currentTimeMillis());
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
+            resp.getWriter().write("Async dispatch worked: " + sdf.format(date) + "\n");
         } else {
             resp.setContentType("text/plain");
             final AsyncContext actx = req.startAsync();

Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async2.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async2.java?rev=1709743&r1=1709742&r2=1709743&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async2.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/async/Async2.java Wed Oct 21 08:05:44 2015
@@ -17,6 +17,8 @@
 package async;
 
 import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 import javax.servlet.AsyncContext;
 import javax.servlet.ServletException;
@@ -34,7 +36,8 @@ public class Async2 extends HttpServlet
     private static final Log log = LogFactory.getLog(Async2.class);
 
     @Override
-    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+    protected void service(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException {
         final AsyncContext actx = req.startAsync();
         actx.setTimeout(30*1000);
         Runnable run = new Runnable() {
@@ -45,7 +48,10 @@ public class Async2 extends HttpServlet
                     log.info("Putting AsyncThread to sleep");
                     Thread.sleep(2*1000);
                     log.info("Writing data.");
-                    actx.getResponse().getWriter().write("Output from background thread. Time:"+System.currentTimeMillis()+"\n");
+                    Date date = new Date(System.currentTimeMillis());
+                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
+                    actx.getResponse().getWriter().write(
+                            "Output from background thread. Time: " + sdf.format(date) + "\n");
                     actx.complete();
                 }catch (InterruptedException x) {
                     log.error("Async2",x);

Modified: tomcat/trunk/webapps/examples/jsp/async/async1.jsp
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/jsp/async/async1.jsp?rev=1709743&r1=1709742&r2=1709743&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/jsp/async/async1.jsp (original)
+++ tomcat/trunk/webapps/examples/jsp/async/async1.jsp Wed Oct 21 08:05:44 2015
@@ -14,13 +14,15 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 --%>
-<%@page session="false"%>
+<%@page session="false" import="java.util.Date,java.text.SimpleDateFormat"%>
 Output from async1.jsp
 Type is <%=request.getDispatcherType()%>
 <%
-System.out.println("Inside Async 1");
+  System.out.println("Inside Async 1");
   if (request.isAsyncStarted()) {
     request.getAsyncContext().complete();
   }
+  Date date = new Date(System.currentTimeMillis());
+  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
 %>
-Completed async request at <%=new java.sql.Date(System.currentTimeMillis())%>
\ No newline at end of file
+Completed async request at <%=sdf.format(date)%>
\ No newline at end of file

Modified: tomcat/trunk/webapps/examples/jsp/async/async3.jsp
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/jsp/async/async3.jsp?rev=1709743&r1=1709742&r2=1709743&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/jsp/async/async3.jsp (original)
+++ tomcat/trunk/webapps/examples/jsp/async/async3.jsp Wed Oct 21 08:05:44 2015
@@ -14,7 +14,12 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 --%>
-<%@page session="false"%>
+<%@page session="false" import="java.util.Date,java.text.SimpleDateFormat"%>
 Output from async3.jsp
 Type is <%=request.getDispatcherType()%>
-Completed async 3 request at <%=new java.sql.Date(System.currentTimeMillis())%>
\ No newline at end of file
+<%
+  Date date = new Date(System.currentTimeMillis());
+  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
+%>
+
+Completed async 3 request at <%=sdf.format(date)%>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org