참고: Java 8은 2024년 1월 31일 지원 종료되었습니다. 기존 Java 8 애플리케이션은 계속 실행되고 트래픽을 수신합니다. 그러나 지원 종료 날짜 이후에는 해당 런타임을 사용하는 애플리케이션의 재배포를 App Engine에서 차단할 수 있습니다.
지원되는 최신 Java 버전으로 마이그레이션하는 것이 좋습니다.
<!-- 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.// ...}}
이 큐에 추가된 태스크는 URL /worker에서 매개변수 key로 요청 핸들러를 호출하여 실행됩니다. queue.xml 파일에 설정된 속도 또는 초당 태스크 5개의 기본 속도로 실행됩니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-03-06(UTC)"],[[["This content demonstrates how to add a task to a queue using legacy bundled services and APIs within the first-generation App Engine standard environment."],["The provided `index.html` includes a form to submit a value (`key`) to the `/enqueue` URL for task queuing."],["The `Enqueue.java` servlet handles POST requests to `/taskqueues/enqueue`, adding tasks with the provided `key` to the default queue."],["The `Worker.java` servlet, mapped to `/taskqueues/worker`, processes the tasks, receiving the `key` parameter for execution."],["Tasks in the queue are executed by calling the `/worker` request handler, with the rate determined by the `queue.xml` file or defaulting to 5 tasks per second."]]],[]]