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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:19:59+00:00 2026-06-14T11:19:59+00:00

Currently I have a Thread running a Socket listening for connections. When it receives

  • 0

Currently I have a Thread running a Socket listening for connections. When it receives a connection, it needs to upload data gathered in the main thread (i.e. grab data from main thread). However I pass an instance of the Object, but it’s never updated with the data that’s collected while waiting for a connection.

Is there a proper way to do this? I’ve googled around and can’t seem to find a concrete answer.

Could someone point me in the right direction?


Hopefully this makes sense, but i’ll try to explain more with an examples.

class MainThread {
    private void MainThread() {
        SomeObj obj = new SomeObj("DATA Needed");

        SecondThread second = new SecondThread(obj);
        second.start();
    }
}

class SecondThread extends Thread {
    SomeObj obj;

    public void SecondThread(Object obj) {
    this.obj = obj;
    }
    public void run() {

    //Listening for connection
    //Connection get!
    //Get updated data (Object obj) from main thread.
    //Upload
    }
}

I appreciate any help you can give me. Please let me know if I am approaching this completely wrong! I would rather learn AND get answers than just get answers.

Thanks so much!

  • 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-14T11:20:00+00:00Added an answer on June 14, 2026 at 11:20 am

    When it receives a connection, it needs to upload data gathered in the main thread (i.e. grab data from main thread).

    This doesn’t make sense as you don’t get information from Threads, you get information and communicate with Objects. That’s a big difference. You need to pass an instance of the object that you need information from into the second object that needs this information, perhaps as a parameter in its constructor. Then you would set a field in your SecondThread class with this instance and you can call methods on it.

    i.e.,

    class MainThread {
        private void MainThread() {
            SomeType obj = new SomeType("DATA Needed");
    
            SecondThread second = new SecondThread(obj);
            second.start();
        }
    }
    
    class SecondThread extends Thread {
        SomeType obj;
    
        public SecondThread(SomeType obj) {
           this.obj = obj;
        }
        public void run() {
          // can call methods on obj here
        }
    }
    

    Hopefully you’re not actually using an Object type but rather a much more specific type of object, right?

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

Sidebar

Related Questions

I currently have two threads running in my program: Main thread - Grabs image
I have read that Thread.sleep() will pause the currently running thread for the time
I currently have a long running thread which uses a hibernate session to perform
I currently have a tomcat container -- servlet running on it listening for requests.
I currently have a thread that I created using CreateRemoteThread(). Everything works great. Upon
Currently have password protection on my main and sub directories, however I'd like to
I have a receive thread listening with the BluetoothServerSocket accept() call. This thread will
I currently have my project running two separate threads (one for MFC operations, like
Here's the situation, I have a thread running that is partially controlled by code
I found the following semaphore example. I'm currently learning about thread syncing. I have

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.