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 dell'API Modules
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
L'API Modules fornisce funzioni che restituiscono informazioni sull'ambiente operativo corrente (modulo, versione ed istanza).
L'API Modules dispone anche di funzioni che recuperano l'indirizzo di un modulo, di una
versione o di un'istanza. In questo modo un'applicazione può inviare richieste da un'istanza all'altra, sia negli ambienti di sviluppo che di produzione.
Il seguente esempio di codice mostra come ottenere il nome del modulo e l'ID istanza per
una richiesta:
import com.google.appengine.api.modules.ModulesService;
import com.google.appengine.api.modules.ModulesServiceFactory;
ModulesService modulesApi = ModulesServiceFactory.getModulesService();
// Get the service name handling the current request.
String currentModuleName = modulesApi.getCurrentModule();
// Get the instance handling the current request.
int currentInstance = modulesApi.getCurrentInstance();
L'ID istanza di un modulo con scalabilità automatica verrà restituito come valore codificato in base64 univoco, ad esempio e4b565394caa
.
Puoi comunicare tra i moduli della stessa app recuperando il nome host del modulo di destinazione:
Il seguente esempio di codice mostra come ottenere il nome del modulo e l'ID istanza per
una richiesta:
import com.google.appengine.api.modules.ModulesService;
import com.google.appengine.api.modules.ModulesServiceFactory;
import java.net.MalformedURLException;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
// ...
ModulesService modulesApi = ModulesServiceFactory.getModulesService();
// ...
try {
URL url = new URL("http://" +
modulesApi.getVersionHostname("my-backend-service","v1") +
"/fetch-stats");
BufferedReader reader = new BufferedReader(
new InputStreamReader(url.openStream()));
String line;
while ((line = reader.readLine()) != null) {
// Do something...
}
reader.close();
} catch (MalformedURLException e) {
// ...
} catch (IOException e) {
// ...
}
Puoi anche utilizzare il servizio Ricerca URL.
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\u003eThe Modules API provides functions to retrieve information about the current operating environment, including module, version, and instance details.\u003c/p\u003e\n"],["\u003cp\u003eThis API enables applications to obtain the address of a specific module, version, or instance, facilitating communication between instances in both development and production.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eModulesServiceFactory\u003c/code\u003e class is used to access the Modules API, allowing developers to get the current module name and instance ID, among other information.\u003c/p\u003e\n"],["\u003cp\u003eModules can communicate with each other by fetching the hostname of the target module using \u003ccode\u003egetVersionHostname\u003c/code\u003e function, which will then require the use of a URL to retrieve it.\u003c/p\u003e\n"],["\u003cp\u003eFor those updating to the App Engine Java 11/17 runtime, there is a specific migration guide that outlines the migration options for legacy bundled services.\u003c/p\u003e\n"]]],[],null,["# Using the Modules API\n\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\nThe Modules API provides functions that return information about the current\noperating environment (module, version, and instance).\n\nThe Modules API also has functions that retrieve the address of a module, a\nversion, or an instance. This allows an application to send requests from one\ninstance to another, in both the development and production environments.\n\nThe following code sample shows how to get the module name and instance id for\na request: \n\n import com.google.appengine.api.modules.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.modules.ModulesService.html;\n import com.google.appengine.api.modules.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.modules.ModulesServiceFactory.html;\n\n https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.modules.ModulesService.html modulesApi = https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.modules.ModulesServiceFactory.html.getModulesService();\n\n // Get the service name handling the current request.\n String currentModuleName = modulesApi.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.modules.ModulesService.html#com_google_appengine_api_modules_ModulesService_getCurrentModule__();\n // Get the instance handling the current request.\n int currentInstance = modulesApi.getCurrentInstance();\n\nThe instance ID of an automatic scaled module will be returned as a unique\nbase64 encoded value, e.g. `e4b565394caa`.\n\nYou can communicate between modules in the same app by fetching the hostname of\nthe target module:\n\nThe following code sample shows how to get the module name and instance id for\na request: \n\n import com.google.appengine.api.modules.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.modules.ModulesService.html;\n import com.google.appengine.api.modules.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.modules.ModulesServiceFactory.html;\n\n import java.net.MalformedURLException;\n import java.net.URL;\n import java.io.BufferedReader;\n import java.io.InputStreamReader;\n import java.io.IOException;\n\n // ...\n\n https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.modules.ModulesService.html modulesApi = https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.modules.ModulesServiceFactory.html.getModulesService();\n\n // ...\n try {\n URL url = new URL(\"http://\" +\n modulesApi.https://cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.modules.ModulesService.html#com_google_appengine_api_modules_ModulesService_getVersionHostname_java_lang_String_java_lang_String_(\"my-backend-service\",\"v1\") +\n \"/fetch-stats\");\n BufferedReader reader = new BufferedReader(\n new InputStreamReader(url.openStream()));\n String line;\n\n while ((line = reader.readLine()) != null) {\n // Do something...\n }\n reader.close();\n\n } catch (MalformedURLException e) {\n // ...\n } catch (IOException e) {\n // ...\n }\n\nYou can also use the [URL Fetch](/appengine/docs/legacy/standard/java/issue-requests) service."]]