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!

Financial Services Industry Use Cases, ITSI Best Practices, and More New Articles ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Splunk Federated Analytics for Amazon Security Lake

Thursday, November 21, 2024  |  11AM PT / 2PM ET Register Now Join our session to see the technical ...

Splunk With AppDynamics - Meet the New IT (And Engineering) Couple

Wednesday, November 20, 2024  |  10AM PT / 1PM ET Register Now Join us in this session to learn all about ...