1 |
torben |
645 |
/* this example old-school Thread / Runnable's - which should under no circumstances be used from a java EE environment.
|
2 |
|
|
*
|
3 |
|
|
* This is only for documentation purposes .... if you need to run async code, you should investigate some of the other examples
|
4 |
|
|
*
|
5 |
|
|
* There's no guarantee that this will ever work on your chosen java container.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
package dk.thoerup.asyncsamples;
|
9 |
|
|
|
10 |
|
|
import java.io.IOException;
|
11 |
|
|
import java.util.logging.Logger;
|
12 |
|
|
|
13 |
|
|
import javax.servlet.ServletException;
|
14 |
|
|
import javax.servlet.http.HttpServlet;
|
15 |
|
|
import javax.servlet.http.HttpServletRequest;
|
16 |
|
|
import javax.servlet.http.HttpServletResponse;
|
17 |
|
|
|
18 |
|
|
public class SimpleThreading extends HttpServlet {
|
19 |
|
|
|
20 |
|
|
static final Logger logger = Logger.getLogger( SimpleThreading.class.getName() );
|
21 |
|
|
|
22 |
|
|
class Worker implements Runnable {
|
23 |
|
|
@Override
|
24 |
|
|
public void run() {
|
25 |
|
|
DummyWork.doWork();
|
26 |
|
|
}
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
30 |
|
|
response.getWriter().write("Starting async thread");
|
31 |
|
|
|
32 |
|
|
Thread t = new Thread( new Worker() );
|
33 |
|
|
t.start();
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
}
|