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 8461159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:48:11+00:00 2026-06-10T13:48:11+00:00

I have a java appengine app with true. I know that multiple threads will

  • 0

I have a java appengine app with true. I know that multiple threads will be running on a single instance handling multiple concurrent requests. I understand that the code must be threadsafe, i.e. no global static variables.

What I don’t understand is whether the thread is killed when the request is over, or whether the same thread can be used to process another incoming request once its done processing one.

Why does this matter? Some details:

I have a static class with a thread local variable as such:

public abstract class Foo {
    private static final ThreadLocal<Boolean> threadIsApiCall = new ThreadLocal<Boolean>();
    static {
         setIsApiCall(false);
    }
}

This variable stores whether the current request for this thread is a call to our rest api or whether its a call from our own custom client. This variable only gets set if a filter matching our api paths runs. The issue I’m running into is that if a request is made to our API, and the threadlocal variable gets set to true, on subsequent requests (that arent api requests) the threadlocal variable is still set to true. You would suspect that it would be set to false because of the static initializer. The only way it could be set to true still is if the initializer doesn’t run which leads me to believe threads are reused. Is this true?

  • 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-10T13:48:12+00:00Added an answer on June 10, 2026 at 1:48 pm

    Thread reuse is an implementation detail of the servlet implementation. Threads are normally reused via thread pool. This can typically be configured via a servlet configuration. Unfortunately this is not the case with GAE.

    You can simply check if GAE recycles threads by logging Thread.currentThread().getName().

    Because of the possible thread reuse, use of ThreadLocal in servlets was always a bad idea. Use servletRequest.setAttribute(..) if you need to store some data in request-scope.

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

Sidebar

Related Questions

I have a little app that runs fine on local dev appengine, but appengine
I'm trying to get the server URL of a currently running appengine java app
I currently have a Java application running on Google App Engine, but I want
I currently have a Java application running on Google App Engine, but I want
I have a Java Google App Engine web application that allows user upload of
I have a small AppEngine app that enables me to add YouTube videos to
we have app hosted on google app engine for java. In this app we
I have an application hosted in Java on AppEngine and I would like to
I have java sdk 1.7. I've always used django/python for web development, this will
I have Java Map (out of Strings and Ints) objects that I want 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.