| 42 | actx.setTimeout(30*1000); |
| 43 | Runnable run = new Runnable() { |
| 44 | @Override |
| 45 | public void run() { |
| 46 | try { |
| 47 | Thread.currentThread().setName("Async2-Thread"); |
| 48 | log.info("Putting AsyncThread to sleep"); |
| 49 | Thread.sleep(2*1000); |
| 50 | log.info("Writing data."); |
| 51 | Date date = new Date(System.currentTimeMillis()); |
| 52 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); |
| 53 | actx.getResponse().getWriter().write( |
| 54 | "Output from background thread. Time: " + sdf.format(date) + "\n"); |
| 55 | actx.complete(); |
| 56 | }catch (InterruptedException | IllegalStateException | IOException x) { |
| 57 | log.error("Async2",x); |
| 58 | } |
| 59 | } |
| 60 | }; |
| 61 | Thread t = new Thread(run); |
| 62 | t.start(); |