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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:01:48+00:00 2026-06-18T07:01:48+00:00

In a java program, I am running same function across multiple threads. What I

  • 0

In a java program, I am running same function across multiple threads.
What I want to do is this–

  1. Identify specific running threads– eg if there are 2 running threads how can I access one of those threads from an external function? (The external function is part of the same java app that has the threads)
  2. Suppose there is a variable named “x” that is being used across both the threads above. Can I store and retrieve separate values for “x” in thread1 and thread2? Is this the default behaviour for any variable used in a thread?
  3. Access/update values of variables in a specific thread– eg I wish to update value of “x” as it is being used in “thread 1”.
  4. Terminate one (specific) running thread. Eg I wish to terminate Thread1 (from the 2 running threads above).
  • 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-18T07:01:49+00:00Added an answer on June 18, 2026 at 7:01 am

    Answers for

    1. There are couple of Ways to do this. You can either;
      A Util class named ThreadUtil and inside have a static Set<Thread>. You can add the threads you create to set and remove whenever the thread finishes executing.
      Or you can extend from ThreadPoolExecutor and override methods beforeExecute, afterExecute methods to do the same thing above. The you can use the set to get the running threads. You can use a map if you want to store and retrieve by name.
    2. This is possible by using ThreadLocal class. See this post on how to use ThreadLocal
    3. Possible with ThreadLocal
    4. You can make use of a Flag (boolean stop) in the thread to do this, and a method to set this flag to true
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When running a java program using the java command you can specify the verbose
Say suppose I am running a java program through command line. And this program
I am running the same java program on a windows and on a linux
I have a java program that is running in the background(Windows). I would like
I now have a running Java program which only lacks of the final step,that
I am running a Java program that connect 1000 clients to a server at
I'm running a java program that uses many vectors. I'm afraid my use of
I am having trouble running a Java program with Windows Powershell 2.0. Any help
I am running Java 6 on a Linux machine (RHEL 5) and my program
I get the following error when running mongo-hadoop streaming: java.io.IOException: Cannot run program "mapper.py":

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.