My question is similar to this one, but with regard to Java instead of Python.
How can I force some Java code to run whenever a new instance of a Google App Engine server starts?
Thanks!
js, Java, Ruby, C#, Go, Python, or PHP. A fully managed environment lets you focus on code while App Engine manages infrastructure concerns. Use Cloud Monitoring and Cloud Logging to monitor the health and performance of your app and Cloud Debugger and Error Reporting to diagnose and fix bugs quickly.
Run eclipse. To download and install the Cloud Tools for Eclipse plugin, select Help > Eclipse Marketplace... and search for Google Cloud. After installation, restart Eclipse when prompted to do so. In Eclipse, select the File menu > New > Google App Engine Standard Java Project.
in google app engine, your java code is executed within the servlet environment. thus, you could define listeners to boostrap your startup code. to do this, you need to implement your startup code in the listener and define the listener in your web.xml:
listner class:
package test;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class MyContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
// startup code here
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// shutdown code here
}
}
web.xml:
<web-app>
<listener>
<listener-class>test.MyContextListener</listener-class>
</listener>
<!-- your other web configuration -->
</web-app>
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