Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:49:47+00:00 2026-06-10T15:49:47+00:00

What is the proper scope for App Engine services when creating a servlet: static,

  • 0

What is the proper scope for App Engine services when creating a servlet: static, instance, or local? And what are the implications of each? It seems like you should want to use them in as wide a scope as possible, to avoid the overhead of re-creating (or re-retrieving) them, but I wonder as to whether this will cause improper reuse of data, especially if <threadsafe>true</threadsafe>.


Examples of each scope are provided below. MemcacheService will be used in the examples below, but my question applies to any and all services (though I’m not sure if the answer depends on the service being used). I commonly use MemcacheService, DatastoreService, PersistenceManager, ChannelService, and UserService.

Static scope:

public class MyServlet extends HttpServlet {
    private static MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService();

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
        memcacheService.get("x");
    }
}

Instance member:

public class MyServlet extends HttpServlet {
    private MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService();

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
        memcacheService.get("x");
    }
}

Local scope:

public class MyServlet extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
        MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService();
        memcacheService.get("x");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:49:49+00:00Added an answer on June 10, 2026 at 3:49 pm

    GAE is a distributed system where all of it’s services run on separate servers. So when you invoke a service it internally serializes the request (afaik with protocol buffers) sends it to the server running the service, retrieves the result and deserializes it.

    So all of *Service classes are basically pretty thin wrappers around serialization/deserialization code. See for example source of MemcacheService.

    About scope: there is no need to optimize on *Service classes as they are pretty thin wrappers and creating them should take negligible time compared to whole service roundtrip.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This yields proper results, but I would like to have the resulting row in
What's the proper way to write? validates_uniqueness_of :a, :scope => [:b, :c], :unless =>
With many browsers adding proper local storage support (and with this whole HTML5 buzz),
I would like to share the data access portion of my grails app (Grails
Let's say that in enclosing scope, I have some variables that each thread in
EDIT : proper solution: void add(Student s) { if(root == null) root = new
xml is not encoding proper - any help List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new
What is the proper method to set the focus onload to first field in
I was looking a proper way to implment a ScaleAnimation. My purpose is to
What's the proper way to add a literal text value from a field to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.