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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:36:27+00:00 2026-05-22T16:36:27+00:00

So I am new to Java, I have done a bit of c programming.

  • 0

So I am new to Java, I have done a bit of c programming.
I am trying to make a virtual network of nodes, each node would need to be a thread.
The nodes are only allowed to talk to their neighbor nodes.
there will be a master node that can talk to any node but the nodes would have to talk to each other to get back to the master node. the master nodes neighbors can talk to the master node.

I was originally going to keep an array list of the nodes, but then I realized all the nodes needed to be there own thread.

My question is how do I pass information back in forward between threads in Java.
I need to be able to have the master node give all the regular nodes position information.
and I need the regular nodes to be able to pass messages to their neighbor regular nodes.?

here are my git repos if you would like to look at the code I got going now.

https://github.com/fieldju/cs372_project

in C I made a program that used pipes for the children to talk to each other and a server connected the clients, but in this problem the nodes to to have p2p communication as most of them can not directly communicate to the master node / server


Just an Update for anyone who looks at this and wants to see the results. I got the nodes up and running and communicating you can check out the code at

https://github.com/fieldju/cs372_project

I am still working on the distance vector stuff and a few other things but by the end of next week the entire thing should be done.

  • 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-22T16:36:27+00:00Added an answer on May 22, 2026 at 4:36 pm

    I was originally going to keep an
    array list of the nodes, but then I
    realized all the nodes needed to be
    there own thread.

    You can keep an array of threads, it would still maintain a thread-per-node with the same logic structure.

    how do I pass information back in
    forward between threads in Java.

    If threads reside in the same process then definitely sockets are an overkill. I would use one or several ConcurrentLinkedQueue instances to push/pop messages.

    One or several really depends on the kind of communication that you are implementing. Maybe one ConcurrentLinkedQueue per node, so nodes push messages to queues and every node knows where from to pop the message.

    Few hints for implementation

    Wrap up all the logic to en-route messages in a class – let’s call this class VirtualNetwork. VirtualNetwork deals with all the instances of ConcurrentLinkedQueue and offers an API of methods to all threads for sending/receiving messages. Make one instance of the class VirtualNetwork accessible to all nodes – by passing a reference to it on the Thread constructor.

    This is an sketch of how your class NodeThread would be. Notice that the classes VirtualNetwork and Message are classes that you have to implement your self.

    class NodeThread extends Thread {
    
        private int nodeId;
        private VirtualNetwork network;
    
        public NodeThread(int nodeId,VirtualNetwork network) {
            this.network = network;
            this.nodeId = nodeId;
        }
        public void run() {
            /* when you have to send */
            int nodeReceptor = this.nodeId -1; /* neighbor in the array of threads */
            Message m = new Message(this.nodeId,nodeReceptor);
            m.setContent(10);
            network.send(m);
    
            /* when you have to receive */
            Message m = network.receive(this.nodeId);
            /* it's your decision to implement this in a blocking way or not */
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done Java and JSP programming in the past, but I am new
I'm a little bit new to objects in Java and I would appreciate some
I am new to Java and would like to know a bit more. I
Hi I am a bit new to programming and recently I have been given
I am new to Java. I just read that class variables in Java have
I'm new to Java and I have a beginner question: NumberFormat is an abstract
I have the following code adding an ActionListener to a JTextField: chatInput.addMouseListener(new java.awt.event.MouseAdapter() {
I'm relatively new to java (specifically swing) and have recently been making some fairly
I am new to Java (and Eclipse) but I have used .NET (and Visual
I'm new to Java, but have some OOP experience with ActionScript 3, so I'm

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.