|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Sep 2001
Città: de_legato
Messaggi: 792
|
[SERVLETv3 & ASYNC]il non riuscire a capire se una cosa fa al caso tuo....
Alur ...da un pò è uscito il Glassfish 3 con pieno supporto alle Servlet v3 che alcuni di voi sapranno finalmente introducono il concetto di Async ....quà un pò di codice, quello della servlet che usa l'async:
Codice:
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import javax.servlet.AsyncContext;
@WebServlet(urlPatterns = "/AsynchServlet", asyncSupported = true)
public class AsynchServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
AsyncContext aCtx = request.startAsync(request, response);
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10);
executor.execute(new AsynchRunnable(aCtx));
}
}
Codice:
import javax.servlet.AsyncContext;
public class AsynchRunnable implements Runnable {
AsyncContext ctx;
public AsynchRunnable(AsyncContext ctx) {
this.ctx = ctx;
}
public void run() {
// Simulate a long-running task such as
// calling a webservice, performing database
// operation, or waiting for a server side
// event (such as receiving a message in
// Comet-enabled environment.
try {
// Sleep for 1000 ms
Thread.sleep(1000);
} catch (Exception ie) {
}
ctx.dispatch("/response.jsp");
}
}
Oppure sono io che mi sbaglio è c'è qualche modo che mi permette di utilizzare un pool fisso di thread senza che qualcuno di questi rimanga bloccato su una read() o write() da e per il client?
__________________
---------------------------------------------- File reality.sys corrupted, Reboot Universe? Y/N ---------------------------------------------- Ultima modifica di Frank1962 : 22-01-2010 alle 12:28. |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 22:00.



















