1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Task Queues in google app engine

Discussion in 'Java' started by hbgipss, Jun 15, 2012.

  1. hbgipss

    hbgipss New Member

    Jun 15, 2012
    Likes Received:
    Trophy Points:
    Home Page:
    First, generate queue.xml file in WEB-INF has content :

    Normal, when you crawl knowledge, at the time, you need send a request to crawl, sequential. & wait webpage to response result. in the event you need to do this working more several times, you need to care their result & it takes a long time to response these working completed . To Resolve these issues, They use Task Queues. They only list our working to resolve. It work automatic & you don't care how to long time it is completed. Example, when you resgister on a forum, you don't wait webpage send e-mail to complete register proccessing, you can view immediate these topics of forum
    <!�Change the refresh rate of the default queue to 1/s�>
    <name>default</name> //name of task queue will call in servlet
    <rate>100/s</rate> //several times use task queues in 1s
    generate one servlet to add task queues(DemoServlet.java)
    package Showsiteinfo.cron;
    import java.io.IOException;
    import javax.jdo.PersistenceManager;
    import javax.jdo.Query;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import com.google.appengine.api.taskqueue.Queue;
    import com.google.appengine.api.taskqueue.QueueFactory;
    import com.google.appengine.api.taskqueue.TaskOptions.Method;
    import static com.google.appengine.api.taskqueue.TaskOptions.Builder.*;
    public class DemoServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
    for(int i=0;i<100;i++)
    Queue queue = QueueFactory.getDefaultQueue();  //call default task queues was config in queue.xml file.
    queue.add(withUrl(“/queue”).method(Method.GET).param(“name”, “abc”));  // call url queue to use method get with parameter name=abc
    Go to web.xml to edit path DemoServlet.java is "/demo"
    Now, we run link "/demo", so, 1s(maybe more 1s), we did 100 request to url/queue.
    Limit of Google : don't allow to us call links from a domain or other app, so only call in itself in app that you are do task queues.
    Last edited by a moderator: Jun 15, 2012

Share This Page