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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:05:40+00:00 2026-06-18T01:05:40+00:00

I have created a number of threads. I know each threads name(suppose through an

  • 0

I have created a number of threads. I know each threads name(suppose through an alien mechanism I set name of thread.) Now I am inside a thread and want to send a message to another thread.

I am trying to code a simulator of Pastry and Chord protocol. I can not have a number of distributed nodes, so I have created a number of threads. Now I want each thread send and receive messages from one another. I have set each nodes name as its IP(a randomly generated number). Now I do not know how to send a message from one node to another. Please tell me how to send a message from one thread to another if you know another threads name.

  • 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-18T01:05:41+00:00Added an answer on June 18, 2026 at 1:05 am

    I would suggest some kind of a message system. The easiest way would be to create a thread-safe FIFO and pass it into each thread. If you want to send messages directly to each different thread, make a “Topic” for each thread.

    Don’t try to hack something in using the thread name, it’ll just constrain you later.

    Pasted from comment so I can parse it:

    private static BlockingQueue[] queue; 
    private static int queueNum = 0; 
    public static void newQueue(String ip) 
    {
        queue[queueNum] = new ArrayBlockingQueue(1024); 
        try{ queue[queueNum].put(ip); }
        catch (InterruptedException e){e.printStackTrace(); } 
        queueNum++; 
    }
    

    Oh, I see your problem. You never assign BlockingQueue a value. Try changing that line to:

    private static BlockingQueue[] queue=new BlockingQueue[10]; 

    That will allow you 10 queues.

    I’d also suggest that instead of an array you use a HashMap so you can name, add and delete queues at will. Instead of being queue[2] you’ll be addressing queue.get(“Thread1Queue”) or something more descriptive.

    Note response to comments:
    A HashMap can generally replace an array, it’s lookup is nearly as quick but it uses anything for an index instead of numbers–Strings, enums, Objects, whatever you want (as long as it has the hash and equals methods overriden), but usually strings.

    So if you are storing a bunch of queues, and you want to name them specifically, you can say:

    HashMap queues=new HashMap();
    queues.put("queue1", new ArrayBlockingQueue(1024));
    queues.put("queue2",new ArrayBlockingQueue(1024));
    ...
    

    Then whenever you want to access one you can use:

    queues.get("queue1").put(new ThingToAddToArrayBlockingQueue())...
    

    to put a “Thing to add” to queue1.

    If you just want a “Bunch” of them and don’t need to know which is which (Just a collection of threads that can be fed generic taskss) there are specific collections/patterns for that in the concurrent package.

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

Sidebar

Related Questions

I have the task of large number of threads running, each doing a small
I have a process that must create and close threads on demand. Each thread
I have created a number of personal libraries to help with my daily coding.
I have created a report which contains a number of parameters so that the
I have created an activity which sends a number of notifications to status bar.
I have created a line chart using Reporting Services that charts the number of
I have created custom cell in which there are n number of image views.
Using xlwDotNet, I have created a simple function which returns one number. Sometimes, something
I have a userform in 2008 vb express edition. A part number is created
I have a listview that contain several EditTexts created dynamically according to the number

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.