Java 8 has reached end of support
and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Java 8
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Java
8 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you
migrate to the latest supported version of Java.
Using the Modules API
Stay organized with collections
Save and categorize content based on your preferences.
The Modules API provides functions that return information about the current
operating environment (module, version, and instance).
The Modules API also has functions that retrieve the address of a module, a
version, or an instance. This allows an application to send requests from one
instance to another, in both the development and production environments.
The following code sample shows how to get the module name and instance id for
a request:
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();
The instance ID of an automatic scaled module will be returned as a unique
base64 encoded value, e.g. e4b565394caa
.
You can communicate between modules in the same app by fetching the hostname of
the target module:
The following code sample shows how to get the module name and instance id for
a request:
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) {
// ...
}
You can also use the URL Fetch service.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-21 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","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"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-21 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,[]]