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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:08:24+00:00 2026-06-12T21:08:24+00:00

I have a centralized socket class which is responsible for sending and retrieving data.

  • 0

I have a centralized socket class which is responsible for sending and retrieving data. I have 2 classes:

  • one which listens to the input stream and
  • the other one which takes care of writing to it.

Listening running on an infinite loop and then process the messages. For synchronous i block the read and reset these values once i receive the response from the server.

Now i am stuck with asycnhronous. I have 3 methods in my service.

  1. getSomething
  2. readSomething
  3. saySomething.

In my getSomething i want to implement async functionality based on the boolean flag provided. When my app starts i also start both of my threads and if i send concurrent request.

For example readSomething first and then getSomething then i get the return value for readSomething in getSomething which is not what i desire and i can see in the logs that the output for getSomething comes after a while.

It looks like the Future object requires to submit a new task which will run in it’s own thread but the way i have design this app, i just can’t create a new thread. Can anyone give me insights on how should i handle this asycnhronous like a flow chart etc ?.

  • 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-12T21:08:25+00:00Added an answer on June 12, 2026 at 9:08 pm

    If you’re doing work Asynchronously, that means that other part of the application does not care when the async work is done.

    What you’ll normally want to do is notify the other part, when the async work is done. For this, you’ll want to use the “Observer Pattern” (the article includes flow-charts).

    The basic idea is, that your app starts the async work and is notified, when the work is done. That way, you can loosely couple two parts of the application. A quick example:

    /**
     * The observer
     */
    public interface AsyncWorkDoneListener{
    
        /**
         * This method will be called when the async-thread is
         *  done.
         */
        public void done(Object unit);
    
    }
    
    /**
     * The worker (which does the asyc-work on another thread).
     */
    public class AsyncWorker{
    
        private AsyncWorkDoneListener listener;
    
        /**
         * Set (you might want to maintain a list here) the current
         *  listener for this "AsyncWorker".
         */
        public void setListener(AsyncWorkDoneListener listener){
            this.listener = listener;
        }
    
        /**
         * Will do the async-work
         */
        public void doWork(){
            // Do the work in another thread...
            // When done, notify the registered listener with the
            //  result of the async work:
            this.listener.done(the_object_containing_the_result);
        }
    }
    
    /**
     * The application
     */
    public class App implements AsyncWorkDoneListener{
    
        public void someMethod(){
            // Work on something asynchronously:
            mAsyncWorker.setListener(this);
            mAsyncWorker.doWork();
        }
    
        @Override
        public void done(Object unit){
            // The asyc work has finished, do something with
            //  the result in "unit".
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
Have deployed numerous report parts which reference the same view however one of them
I have a centralized Mercurial repository which I want to provide access to via
I have one content div with 960px of width and margin 0 auto (centralized),
We have several cron jobs that ftp proxy logs to a centralized server. These
To release my centralized webapp, I COULD have a vhost pointed to some directory
At work, we have several applications with databases in a centralized SQL server. Whenever
Good evening, I would like to have a navigation bar which is centralised to
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I have somewhat of a problem. We have a centralized interface engine that will

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.