GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — updated · MarcosDavidP/Java@6c45a9c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • java-async-servlet/src/main
    • java/com/hmkcode
      • AsyncServlet.java
      • SyncServlet.java
    • webapp
      • WEB-INF
        • web.xml
      • bootstrap
        • css
          • bootstrap.css
        • img
          • glyphicons-halflings-white.png
          • glyphicons-halflings.png
        • js
          • bootstrap.min.js
      • index.html
      • js
        • jquery.1.9.1.min.js
        • myfunctions.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎java-async-servlet/src/main/java/com/hmkcode/AsyncServlet.java‎

Copy file name to clipboardExpand all lines: java-async-servlet/src/main/java/com/hmkcode/AsyncServlet.java
+19-4Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,25 @@
1515
@WebServlet(name="asyncServlet",value = {"/async"},asyncSupported = true)
1616
public class AsyncServlet extends HttpServlet
1717
{
18+
public static int index = 0;
19+
20+
public AsyncServlet(){
21+
System.out.println("AsyncServlet - "+index++);
22+
}
1823

1924
private static final long serialVersionUID = 1L;
2025

26+
String param ="";
2127
@Override
2228
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
2329
throws ServletException, IOException {
2430

31+
2532
final AsyncContext ctx = req.startAsync();
33+
param = ctx.getRequest().getParameter("seq");
34+
2635

27-
ctx.setTimeout(3000);
36+
ctx.setTimeout(0);
2837

2938
ctx.addListener(new AsyncListener() {
3039

@@ -49,19 +58,25 @@ public void onComplete(AsyncEvent arg0) throws IOException {
4958
}
5059
});
5160

52-
5361
ctx.start(new Runnable() {
5462
@Override
5563
public void run() {
56-
// TODO Auto-generated method stub
5764
try {
58-
ctx.getResponse().getWriter().write("Async Started...");
65+
66+
67+
while(!param.equals("exit")){
68+
69+
}
70+
ctx.getResponse().getWriter().write(ctx.getRequest().getParameter("seq"));
71+
5972
} catch (IOException e) {
6073
e.printStackTrace();
6174
}
6275

6376
ctx.complete();
6477
}
78+
79+
6580
});
6681
}
6782
}
Collapse file

‎java-async-servlet/src/main/java/com/hmkcode/SyncServlet.java‎

Copy file name to clipboard
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.hmkcode;
2+
3+
import java.io.IOException;
4+
import javax.servlet.ServletException;
5+
import javax.servlet.annotation.WebServlet;
6+
import javax.servlet.http.HttpServlet;
7+
import javax.servlet.http.HttpServletRequest;
8+
import javax.servlet.http.HttpServletResponse;
9+
10+
11+
@WebServlet(name="syncServlet",value = {"/sync"})
12+
public class SyncServlet extends HttpServlet
13+
{
14+
public static int index = 0;
15+
16+
public SyncServlet(){
17+
System.out.println("SyncServlet - "+index++);
18+
}
19+
20+
private static final long serialVersionUID = 1L;
21+
22+
@Override
23+
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
24+
throws ServletException, IOException {
25+
26+
27+
String seq = req.getParameter("seq");
28+
29+
try {
30+
Thread.sleep(50 * Integer.parseInt(seq));
31+
} catch (NumberFormatException e) {
32+
e.printStackTrace();
33+
} catch (InterruptedException e) {
34+
e.printStackTrace();
35+
}
36+
resp.getWriter().write(seq);
37+
38+
39+
40+
}
41+
}
Collapse file

‎java-async-servlet/src/main/webapp/WEB-INF/web.xml‎

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://java.sun.com/xml/ns/javaee"
4+
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
5+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
6+
id="WebApp_ID" version="3.0">
7+
<display-name>java async servlet</display-name>
8+
<welcome-file-list>
9+
<welcome-file>index.html</welcome-file>
10+
</welcome-file-list>
11+
12+
</web-app>

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.