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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:07:43+00:00 2026-05-25T13:07:43+00:00

I’m working on a Java function that should be called infinitely . This function

  • 0

I’m working on a Java function that should be called infinitely. This function will call a web service that will return back results. Results are then parsed and analysed.

The function should not be called again until the web service returns results, and these results are analysed.

Should I be using infinite recursion to achieve this? Or should I be using a timer that calls the function on certain intervals?

Some questions arise as well:

  1. What happens if the web service’s response times out? How can I prevent the application from crashing or making unlimited calls with no response?

  2. Should I be creating an event driven class to handle these requests?

  3. In terms of optimization, which of the solutions is more efficient?

— Edit

I understand the question is a bit vague and general, so non detailed answers will do just fine, I’ll focus on the implementation. I just need an advice on the approach. 🙂

Any help is appreciated.

  • 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-25T13:07:44+00:00Added an answer on May 25, 2026 at 1:07 pm

    You almost certainly should not use recursion for a process that doesn’t have a definite “base case”. Infinite recursion is a horribly bad idea. Each call eats up more and more of your stack, and eventually you’ll die with an OOM error (or stack overflow, if Java differentiates between the two).

    You could try something like

    private Object mutex = new Object();
    private boolean yourTaskIsRunning = false;
    
    protected void yourTask()
    {
        synchronized(mutex)
        {
            if (yourTaskIsRunning) return;
            yourTaskIsRunning = true;
        }
        try
        {
            // do your thing
        }
        finally
        {
            yourTaskIsRunning = false;
        }
    }
    

    Or, if you can bundle your task into a distinct object, use its being null or not as the “task is running” flag. Create the object in the first synchronized section, start it in the “do your thing” section, and set it to null in the finally block. (Note, either way, you’ll need to ensure that all non-fatal paths through the function — even thrown exceptions! — “clear the flag” when they’re done. Hence the finally block.)

    Either way, you can set up a timer to call this function, and it’ll immediately return if it’s already running. The only drawback with the timer approach is that there might be some downtime between when one call ends and the next begins.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.