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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:48:12+00:00 2026-05-31T01:48:12+00:00

I have 10 identical threads (differentiated only by primary key from 1 to 10)

  • 0

I have 10 identical threads (differentiated only by primary key from 1 to 10) that I create in the main class. In each thread I need to read field in the previous thread i.e. in thread 5 I need to read this field in thread 4. The question is how can I do it?

public class Player extends Thread {

private Integer playerNumber;

public char lastDigit;

public Player(Integer playerNumber) {
    super();
    this.playerNumber = playerNumber;
}

public synchronized char getDigit(){
    return this.lastDigit;
}

public synchronized void setDigit(char digit){
    massage += digit;
    this.lastDigit = digit;
    try {
        Thread.sleep(1);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

public void run(){

}

I need to read the lastDigit field.

Thanks in advance 🙂

  • 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-31T01:48:13+00:00Added an answer on May 31, 2026 at 1:48 am

    Lots of options 🙂 By default, java collections aren’t syncronized:

    You could make a LinkedBlockingQueue in a static variable/class:

    • http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/LinkedBlockingQueue.html

    You could wrap one of the many java collections with the following:

    • Collections.synchronizedMap(..)
    • Collections.synchronizedList(..)
    • Collections.synchronizedSet(..)

    If you don’t mind some complication, but are concerned about GC overhead, use Exchanger (I’d recommend this for your situation):

    • http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Exchanger.html

    If you reallly want to go all out and performance is a major concern, you could use the Disrupter framework (not for the feint of heart):

    • http://code.google.com/p/disruptor/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like my question, i need to generate random numbers that have identical pairs between
I have two identical tables and need to copy rows from table to another.
We have 18 databases that should have identical schemas, but don't. In certain scenarios,
I have 2 SharePoint lists that have identical structures. Is it possible for me
I have several identical elements with different attributes that I'm accessing with SimpleXML: <data>
we have a C++ class which basically reads and writes vectors from a binary
In socket programming, you create a listening socket and then for each client that
I am wanting to append 6 CSVs that have identical layouts and headers together.
I'm looking for an efficient way to query items, that have identical set of
I have this UIView that contains two identical UIImageViews juxtaposed. I am looking 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.