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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:04:50+00:00 2026-06-11T23:04:50+00:00

I’ve got a inner class in my class doing some asynchronous processing and setting

  • 0

I’ve got a inner class in my class doing some asynchronous processing and setting value on parent class. Ex :

class Myclass{
   String test;

   public getTestValueFromMyClass(){
      //this starts asynchronous processing on my inner class
   }

   //inner class
   class InnerClass extends TimerTask{
      //doing something asynchronously, when this process is done
      test = "somevalue";
   }
}

Now here is the problem from Runner class :

class Runner{
    public static void main(String[] args){
       Myclass instance = new Myclass();

       //This is always null because runner class doesn't wait for Inner class to
       //complete asynchronous processing and to set test value
       System.out.println(instance.getTestValueFromMyClass());
    }
}

How do I get around this?

  • 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-11T23:04:51+00:00Added an answer on June 11, 2026 at 11:04 pm

    Others have suggested similar ideas but I’d use a single thread pool with a Callable.

    Your class that is doing the asynchronous processing should implement Callable which will return the computed value. In this example it returns a String but it could also return your own object with more information.

    public class MyClass implements Callable<String> {
       public String call() {
          //doing something asynchronously, when this process is done
          return "somevalue";
       }
    }
    

    Your Runner class would then create a thread pool, fire off the asynchronous task in the background, and then later wait for it to finish. When you submit a Callable job to the thread-pool, you get a Future class back which can be used to wait for the asynchronous job to finish and to get its return value.

    public class Runner{
        public static void main(String[] args) {
           // you can use newFixedThreadPool(...) if you need to submit multiple
           ExecutorService threadPool = Executors.newSingleThreadExecutor();
           // you could store this future in a collection if you have multiple
           Future<String> future = threadPool.submit(new MyClass());
           // after submitting the final job, we _must_ shutdown the pool
           threadPool.shutdown();
    
           // do other stuff in the "foreground" while MyClass runs in the background
    
           // wait for the background task to complete and gets its return value
           // this can throw an exception if the call() method threw
           String value = future.get();
           System.out.println(value);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
i got an object with contents of html markup in it, for example: string
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string

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.