How can one identify whether some code (a serv-let or a simple class) is running on Google App Engine run-time (Java) so that one can decide whether to utilize app engine's specific libraries or not? Is there some reliable runtime enviroment ID for that?
Google App Engine provides four possible runtime environments for applications, one for each of four programming languages: Java, Python, PHP, and Go. The environment you choose depends on the language and related technologies you want to use for developing the application.
This is particularly the case when using the standard environment, since it runs code in a secure sandbox and can deploy and automatically scale applications in seconds. App Engine uses container instances for each deployment.
App Engine supports the following scaling types, which controls how and when instances are created: Automatic (default) Basic. Manual.
Instance classesThe instance class determines the amount of memory and CPU available to each instance, the amount of free quota, and the cost per hour after your app exceeds the free quota. The memory limits vary by runtime generation.
You can check the com.google.appengine.runtime.version
property:
String appEngineVersion = System.getProperty("com.google.appengine.runtime.version");
If it's set, it's App Engine.
But I would consider using separate build targets instead, to avoid the runtime overhead.
similar to what @Reza wrote, but a bit cleaner:
use SystemProperty.environment.value()
to get "Production" when running on App Engine, and "Development" when running in the development server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With