Splunk Dev

Splunk Java API : Why a job object (savedSearch.dispatch()) sometimes never finishes its search

ryoji_solsys
Explorer

Hi,

My code looks something like this.

 // Retrieve the new saved search
    SavedSearch savedSearch = splunk.getSavedSearches().get("SERVICE_CREATED");
    // Run a saved search
            Job jobSavedSearch = null;

            // Run the saved search
            try {
                jobSavedSearch = savedSearch.dispatch();
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
            // Wait for the job to finish
            while (!jobSavedSearch.isDone()) {
                try {
                    Thread.sleep(500);

                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

The problem I am having is that SOMETIMES "jobSavedSearch.isDone()" never being set to true. So it goes into an infinite loop.
I checked the job management on Splunk Web UI and it shows that the status of all the jobs executed are Done.
The saved search is located at a remote instance and I am executing this from my local machine.
Does anyone have a similar issue ?
Is there anything I can do to avoid going into an infinite loop ?

Thanks

Tags (4)

vanessenjonas
Engager

I think i found the answer (at least for my problem) in this post:
https://answers.splunk.com/answers/42271/how-to-search-for-results-using-java-splunk-api.html

job.refresh() inside the job.isDone while.

No clue why this is not commented here:
http://dev.splunk.com/view/java-sdk/SP-CAAAEHQ

aswitzer
Engager

Adding job.refresh() call in my while loop fixed my issues with the standard approach that is documented on the "How to work with searches and jobs using the Splunk SDK for Java" page at dev.splunk.com. Before that the search would hang about 90% of the time. Splunk should seriously consider adding this to their documentation.

Note: This is using version 1.4 of the splunk api. I can't get the 1.5 library to connect because I can't find any current documentation on it.

0 Karma

vanessenjonas
Engager

Hey there,

I have a similar problem. When i fetch jobs over the savedSearch.history() function, everything works fine. But when there's no history and i have to use savedSearch.dispatch() my while over jobSavedSearch.isDone() will end up in an infinite loop. Sadly i have not found any answers yet. I tried it with reportJob.getDoneProgress()!=1.0, but that diddnt work either (plus additionally sometimes gives an exception when the query wasn't started fast enough on the remote server).

0 Karma
Get Updates on the Splunk Community!

How to Monitor Google Kubernetes Engine (GKE)

We’ve looked at how to integrate Kubernetes environments with Splunk Observability Cloud, but what about ...

Index This | How can you make 45 using only 4?

October 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...

Splunk Education Goes to Washington | Splunk GovSummit 2024

If you’re in the Washington, D.C. area, this is your opportunity to take your career and Splunk skills to the ...