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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:21:01+00:00 2026-06-10T12:21:01+00:00

I am writing a class in which I have a List. And I am

  • 0

I am writing a class in which I have a List. And I am instantiating the list from the run method of Runnable. As:

public void sendEmailToLegalUsers() {
    Log.info("JYM====================================");

    try {
        new Runnable() {

            public void run() {
                userCns = new ArrayList<String>();
                recipients = new ArrayList<String>();

                ///other codes
            }
        };                  
    } catch (Exception e) { 
        Log.info("Error occurred in LDAPSendMail: "+ e.getMessage());
    }   

    Log.info("END====================================");
}

Now each time the sendEmailToLegalUsers method will be called there will be a new thread. Now I am wondering is the memory scope of the list is bounded to class level (if it is bounded to class level and if say this method is called two times then what will happen of the list which is created by Thread 1 when there is also a Thread 2) or as the threads run in their own scope then the list will have different scope for each thread. Is there any chance to mixup of the list data between two or multiple thread?

  • 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-10T12:21:03+00:00Added an answer on June 10, 2026 at 12:21 pm

    If you are using the same Runnable class for both of the threads then yes, there will be overlap. If you have a separate new Runnable() for each of your threads then no, they will be separate list instances but this is only if the lists are defined to be local to the Runnable. If the lists are defined in the calling class then the 2nd time you call your method, the userCns and recipients fields will be overwritten.

    In your case, I don’t see any threads being forked at all. All I see is you instantiating the Runnable. Are you sure you aren’t trying to do something like:

        new Thread(new Runnable() {
            public void run() {
                // lists are local to the runnable
                List<String> userCns = new ArrayList<String>();
                List<String> recipients = new ArrayList<String>();
               ///other codes
            }
        }).start();
    

    In this case, each time you call your sendEmailToLegalUsers() method, a new Runnable will be created with new lists.

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

Sidebar

Related Questions

I'm writing a class that have a method of removing an object from other
I'm writing a counter class which doesn't have a nice name yet. It counts
I have a question about best practices in Java. I'm writing a class, which
I am writing a game which uses opengles. I have created my renderer class
I am writing a controller class for my plist, which gets called from another
In the application I am writing, I have a main class which extends the
i m writing one application in which i have created custom list field for
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
I'm writing a class which shares several different features with std::function (or at least
I am writing a template class which takes a floating-point-like type (float, double, decimal,

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.