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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...