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

  • Home
  • SEARCH
  • 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 5955045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:03:29+00:00 2026-05-22T18:03:29+00:00

I actually have three questions.. Let’s say I have a function called CalcualteAge() and

  • 0

I actually have three questions..

Let’s say I have a function called CalcualteAge() and this function is going to be called by several users (Lets think about this as a simple server application providing this function) then how would I handle concurrent function calls between users? (Ex. What happen if user A and user B call the function at the same time

Another question is that the function (CalcualteAge()) is running on a separate thread and it has a return value. Then how would I pass the return value back to the main thread so that main thread can return the value back to the person who called the function.

Last one is that which way is better to implement this? Should I create a new thread and run the function on the thread and terminate the new thread once it finish the calculation? or Should I keep the thread running on background as long as the the application is running?

Thanks in advance.

  • 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-22T18:03:29+00:00Added an answer on May 22, 2026 at 6:03 pm

    If you are doing work on a background thread, you can deliver results on the main thread using a Handler. But the model of “return value from a function” is wrong. You need an asynchronous architecture. The most common one is a call-back function resultAvailable that can be called at any time after the background thread has done its job. The AsyncTask class can help a lot with this.

    Whether to create a separate thread each time or keep a background thread running depends on how frequently you need this calculation done. You might want to use a producer/consumer model for this. There are many examples on the web of how to implement this in Java.

    An alternative architecture, perhaps more appropriate for what you describe, is to set up your calculation code as a Service. Then you can “call” it by constructing an intent with the request and receiving the result. See the guide section on Services for details.

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

Sidebar

Related Questions

I have read other questions on this topic but none that actually answers my
Actually I have two questions. (1) Is there any reduction in processing power or
I have three tables in my DB (actually a few more than that) these
I actually have two questions regarding the same problem but I think it is
I actually have right now two questions: 1) What font faces are preferred for
I actually have two questions regarding exception/error handling in the iPhone app that I
I have three pages on my site. Let's call them home, page2, and page3.
I know there are actually a number of questions similar to this one, but
Let's say I have a simple Login servlet that checks the passed name and
How to use related select boxes in Symfony ? Let's say, I have a

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.