Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

identify whether is code running on app engine runtime (Java)

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?

like image 442
nsegae Avatar asked Nov 10 '10 02:11

nsegae


People also ask

What is runtime environment in Google App Engine?

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.

Does App Engine run containers?

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.

What are the two kinds of instances available in App Engine standard?

App Engine supports the following scaling types, which controls how and when instances are created: Automatic (default) Basic. Manual.

What are instances in App Engine GCP?

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.


2 Answers

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.

like image 144
Matthew Flaschen Avatar answered Oct 10 '22 23:10

Matthew Flaschen


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.

like image 30
Yonatan Maman Avatar answered Oct 10 '22 23:10

Yonatan Maman