<!-- 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>
在 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("/");}}
在 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.// ...}}
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-20。"],[[["\u003cp\u003eThis content demonstrates how to add a task to a queue using legacy bundled services and APIs within the first-generation App Engine standard environment.\u003c/p\u003e\n"],["\u003cp\u003eThe provided \u003ccode\u003eindex.html\u003c/code\u003e includes a form to submit a value (\u003ccode\u003ekey\u003c/code\u003e) to the \u003ccode\u003e/enqueue\u003c/code\u003e URL for task queuing.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eEnqueue.java\u003c/code\u003e servlet handles POST requests to \u003ccode\u003e/taskqueues/enqueue\u003c/code\u003e, adding tasks with the provided \u003ccode\u003ekey\u003c/code\u003e to the default queue.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eWorker.java\u003c/code\u003e servlet, mapped to \u003ccode\u003e/taskqueues/worker\u003c/code\u003e, processes the tasks, receiving the \u003ccode\u003ekey\u003c/code\u003e parameter for execution.\u003c/p\u003e\n"],["\u003cp\u003eTasks in the queue are executed by calling the \u003ccode\u003e/worker\u003c/code\u003e request handler, with the rate determined by the \u003ccode\u003equeue.xml\u003c/code\u003e file or defaulting to 5 tasks per second.\u003c/p\u003e\n"]]],[],null,[]]