Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
El siguiente código agrega una tarea a una cola con opciones.
En index.html:
<!-- A basic index.html file served from the "/" URL. -->
<html>
<body>
<p>Enqueue a value, to be processed by a worker.</p>
<form action="/enqueue" method="post">
<input type="text" name="key">
<input type="submit">
</form>
</body>
</html>
En Enqueue.java:
// The Enqueue servlet should be mapped to the "/enqueue" URL.// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.@WebServlet(name="TaskEnque",description="taskqueue: Enqueue a job with a key",urlPatterns="/taskqueues/enqueue")publicclassEnqueueextendsHttpServlet{protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{Stringkey=request.getParameter("key");// Add the task to the default queue.Queuequeue=QueueFactory.getDefaultQueue();queue.add(TaskOptions.Builder.withUrl("/worker").param("key",key));response.sendRedirect("/");}}
En Worker.java:
// The Worker servlet should be mapped to the "/worker" URL.// With @WebServlet annotation the webapp/WEB-INF/web.xml is no longer required.@WebServlet(name="TaskWorker",description="TaskQueues: worker",urlPatterns="/taskqueues/worker")publicclassWorkerextendsHttpServlet{privatestaticfinalLoggerlog=Logger.getLogger(Worker.class.getName());protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{Stringkey=request.getParameter("key");// Do something with key.// ...}}
Las tareas que se agregan a esta cola se ejecutarán mediante una llamada al controlador de la solicitud en la URL /worker con el parámetro key. Se ejecutarán a la velocidad establecida en el archivo queue.xml o a la velocidad predeterminada de 5 tareas por segundo.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2024-12-05 (UTC)"],[],[]]