Java 8 ha raggiunto la fine del supporto
e verrà
ritirato
il 31 gennaio 2026. Dopo il ritiro, non potrai eseguire il deployment di applicazioni Java 8, anche se la tua organizzazione ha utilizzato in precedenza un criterio dell'organizzazione per riattivare i deployment di runtime legacy. Le tue applicazioni Java 8 esistenti continueranno a essere eseguite e a ricevere traffico dopo la
data di ritiro. Ti consigliamo di
eseguire la migrazione all'ultima versione supportata di Java.
Utilizzo delle code in modalità pull in Java
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina fornisce una panoramica delle code pull nell'ambiente standard di App Engine.
Nelle code push le attività vengono inviate a un servizio di worker in base alla configurazione della coda. Nelle code pull, il servizio worker deve chiedere alla coda le attività. La coda risponde consentendo a questo worker l'accesso esclusivo per elaborare l'attività per un periodo di tempo specificato, chiamato lease.

Utilizzando le code pull, puoi anche raggruppare le attività correlate utilizzando i tag e poi configurare il worker in modo da estrarre più attività con un determinato tag contemporaneamente. Questa procedura è chiamata batching.
Se un worker non riesce a elaborare un'attività prima della scadenza del lease, può rinnovarlo o lasciarlo scadere, a quel punto un altro worker può acquisirlo. Una volta completato il lavoro associato a un'attività, l'operatore deve eliminarla.
L'utilizzo delle code pull richiede che il codice gestisca alcune funzioni automatiche nelle code push:
- Scalabilità dei worker
- Il tuo codice deve scalare il numero di worker in base al volume di elaborazione. Se il codice non gestisce la scalabilità, rischi di sprecare risorse di calcolo se non ci sono attività da elaborare e rischi anche di avere latenza se hai troppe attività da elaborare.
- Eliminazione delle attività
- Il codice deve anche eliminare esplicitamente le attività dopo l'elaborazione.
Nelle code push, App Engine elimina le attività per te. Se il tuo worker non elimina le attività della coda pull dopo l'elaborazione, un altro worker le rielaborerà. Ciò comporta uno spreco di risorse di calcolo e rischia di generare errori se le attività non sono idempotenti.
Le code pull nell'ambiente standard di App Engine vengono create impostando una proprietà in un
file di configurazione denominato queue.xml
.
Flusso di lavoro della coda in modalità pull
I worker che elaborano le attività dalle code pull devono essere definiti in un servizio in esecuzione nell'ambiente standard di App Engine.
Il flusso di lavoro è il seguente:
- Crea una coda in modalità pull utilizzando
queue.xml
.
- Crei attività e le aggiungi alla coda.
- Il worker che hai creato noleggia l'attività utilizzando TaskQueue.
- App Engine invia i dati dell'attività al worker nella risposta del lease.
- Il worker elabora l'attività. Se l'attività non viene eseguita prima della scadenza del contratto di locazione, il collaboratore può modificarne la durata. Se il leasing scade, la tâche potrà essere concessa in leasing a un altro lavoratore.
- Una volta elaborata correttamente, l'attività viene eliminata dal worker.
Passaggi successivi
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-09-04 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003ePull queues in the App Engine standard environment require worker services to actively request tasks, unlike push queues where tasks are automatically delivered.\u003c/p\u003e\n"],["\u003cp\u003eWorkers using pull queues can utilize task grouping with tags and batching to handle related tasks efficiently.\u003c/p\u003e\n"],["\u003cp\u003ePull queue workers must manage scaling and explicitly delete tasks after processing to prevent resource waste and errors.\u003c/p\u003e\n"],["\u003cp\u003eThe pull queue workflow involves creating queues and tasks, leasing tasks to workers, processing tasks, and then deleting completed tasks.\u003c/p\u003e\n"],["\u003cp\u003ePull queues are configured using a \u003ccode\u003equeue.xml\u003c/code\u003e file within the App Engine standard environment.\u003c/p\u003e\n"]]],[],null,["# Using Pull Queues in Java\n\nThis page provides an overview of pull queues in the App Engine\nstandard environment.\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| java-gen2\n|\n| /services/access). If you are updating to the App Engine Java 11/17 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/java-differences) to learn about your migration options for legacy bundled services.\n\nIn *push* queues tasks are delivered to a worker service\nbased on the queue's configuration. In *pull* queues the worker service must *ask*\nthe queue for tasks. The queue responds by allowing that worker unique access\nto process the task for a specified period of time, which is called a *lease*.\n\nUsing pull queues, you can also group related tasks using tags and then configure your\nworker to pull multiple tasks with a certain tag all at once. This process is\ncalled *batching*.\n\nIf a worker cannot process a task before its lease expires, it can either renew the\nlease or let it expire, at which point another worker can acquire it. Once the\nwork associated with a task is complete, the worker must delete it.\n\nUsing pull queues requires your code to handle some functions that are automated\nin push queues:\n\nScaling your workers\n: Your code needs to scale the number of workers based on\n processing volume. If your code does not handle scaling, you risk\n wasting computing resources if there are no tasks to process; you also risk\n latency if you have too many tasks to process.\n\nDeleting the tasks\n: Your code also needs to explicitly delete tasks after processing.\n In push queues, App Engine deletes the tasks for you. If your worker does\n not delete pull queue tasks after processing, another worker will re-process\n the task. This wastes computing resources and risks errors if tasks are\n not [idempotent](https://wikipedia.org/wiki/Idempotence).\n\nPull queues in the App Engine standard environment are created by setting a property in a\nconfiguration file called `queue.xml`.\n\nPull queue workflow\n-------------------\n\nWorkers that process tasks from pull queues must be defined within a service that runs\nin the App Engine standard environment.\n\nThe workflow is as follows:\n\n1. You [create a pull queue](/appengine/docs/legacy/standard/java/taskqueue/pull/creating-pull-queues), using `queue.xml`.\n2. You [create tasks](/appengine/docs/legacy/standard/java/taskqueue/pull/creating-tasks) and add them to the queue.\n3. The worker you have created [leases the task](/appengine/docs/legacy/standard/java/taskqueue/pull/leasing-pull-tasks), using [TaskQueue.](/appengine/docs/legacy/standard/java/javadoc/com/google/appengine/api/taskqueue/package-summary)\n4. App Engine sends task data to the worker in the lease response.\n5. The worker processes the task. If the task fails to execute before the lease expires, the worker can modify the lease duration. If the lease expires, the task will be available to be leased to another worker.\n6. After a task is processed successfully, the [worker deletes it](/appengine/docs/legacy/standard/java/taskqueue/pull/leasing-pull-tasks#deleting-tasks).\n\nWhat's next\n-----------\n\n- Learn how to [create pull queues](/appengine/docs/legacy/standard/java/taskqueue/pull/creating-pull-queues)."]]