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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:42:35+00:00 2026-05-23T20:42:35+00:00

My program will use threads, but some variables like a collection of links/pages, information

  • 0

My program will use threads, but some variables like a collection of links/pages, information about queries (if is updating or none) and some others informations(boolean fields, int fields, etc.) must be shared by the threads.

In this case, all the threads will be processing the same work, but in diferrente elements of a collection.

I want to know if there is a way to do this that don’t be create a class/object only to hold these shared data.

My situation: I have a lot of pages in the database that will need to be processed, and I cant recover all in one time. In each thread, I have a boolean field to inform if the list of pages is being updated with links from database or not. Each thread has a collection with the pages to process.

In a past programa, I had similar situation. To solve it, I create a Master that hold these states and Slaves that get the infos from the Master. But now I want to do without the Master, work only with the Slaves, but I need to know if there is a way to have only one variable for all threads.

Example: if thread1 update some boolean to true, automatically, all the another threads have this boolean as 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-05-23T20:42:35+00:00Added an answer on May 23, 2026 at 8:42 pm

    If you need to share data between threads you need to make sure it is shared in a synchronized fashion, i.e., that the data structures are thread safe.

    Have a look at the java.util.concurrent package. You could perhaps for instance make use of one of the BlockingQueue implementations (ArrayBlockingQueue, DelayQueue, LinkedBlockingDeque, LinkedBlockingQueue, PriorityBlockingQueue, SynchronousQueue).


    Regarding your comment: Have a look also at the java.util.concurrent.atomic package. There you’ll find classes such as AtomicBoolean, AtomicInteger, AtomicReference and so on.


    Example: if thread1 update some boolean to true, automatically, all the another threads have this boolean as true.

    I’d suggest you use an AtomicBoolean in such case. You could presumably also use an ordinary boolean as long as you declare it volatile (if you don’t need compare-and-set operations etc that is).

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

Sidebar

Related Questions

I'm writing a program which will use scan conversion on triangles to fill in
My program will take arbitrary strings from the internet and use them for file
What program can I use to decompile a class file? Will I actually get
I am making an application that does some custom image processing. The program will
As we all know Java program will start executing from the public static void
When deploying the application to the device, the program will quit after a few
I have an executable that is started by a windows service, this program will
I decided to teach myself assembly language. I have realized that my program will
I have a program that will calculate the minimal area taken by fitting rectangles
Is there a program that will print a nicely formatted tree from XML data?

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.