简体   繁体   English

google appengine中java后端的示例代码

[英]sample code for java backend in google appengine

When i read doc of backend its tells how to configure ,etc.What what the code of a backend looks like?Is it just a servlet with extra entries in backend.xml file? 当我阅读后端文档时,它会告诉你如何配置,等等后端的代码是什么样的?它只是一个在backend.xml文件中有额外条目的servlet吗?

I tried to create a servlet with class com.xyz.Mybackend and servlet name Mybackend. 我尝试使用类com.xyz.Mybackend和servlet名称Mybackend创建一个servlet。

public Mybackend  extends HttpServlet{

 public void doGet(HttpServletRequest req, HttpServletResponse resp){

   while(true){
     //do something
     try{
      Thread.sleep(xyz);
     }catch(Exception ex){

     }
   }

}

Then i added following lines in backend.xml 然后我在backend.xml中添加了以下行

<backends>
    <backend name="Mybackend">
    <class>B1</class>
    <options>
    <dynamic>true</dynamic>
    </options>
    </backend>
</backends>

Is that correct/enough?If yes.How to i start my backend now?It it by calling the backend servlet url? 这是正确/足够吗?如果是的话。我现在如何开始我的后端?通过调用后端servlet url它?

http://localhost/mybackenurl ? http://localhost/mybackenurl

  1. Yes, backends are just servlets. 是的,后端只是servlet。

  2. You have to start backends manually via appcfg script: https://developers.google.com/appengine/docs/java/backends/overview#Backend_States 您必须通过appcfg脚本手动启动后端: https//developers.google.com/appengine/docs/java/backends/overview#Backend_States

I know what you mean. 我明白你的意思。 I would have found the whole backends overview section a lot clearer the first time I read it if right at the top it said, backends are just special instances of servlets. 我会在第一次读到它时发现整个后端概述部分更清晰,如果它在顶部说它,后端只是servlet的特殊实例。

A popular way of starting a backends noone here has mentioned is by using push queues, as documented here, https://developers.google.com/appengine/docs/java/taskqueue/overview-push#Java_Push_queues_and_backends 这里提到的一种流行的启动后端的方法是使用推送队列,如此处所述, https://developers.google.com/appengine/docs/java/taskqueue/overview-push#Java_Push_queues_and_backends

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM