Splunk Dev

Running realtime search using the java sdk

preben12
Communicator

Hi

When using the realtime api to search is have noticed that unless you do a extra Thread.Sleep(xxx);
after the job.isReady loop you get an empty stream.

I use the com.splunk.examples.search_realtime.Program as an example.
.....

while (!job.isReady()) {
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        // You shouldn't ever get here.
    }
}
// extra sleep to make sure Splunk returns a event stream.
try {
    Thread.sleep(2000);
} catch (InterruptedException e1) {
}

In another process I continuously ingest tweet events into an index, but they are not showing up when running the Program unless the extra Thread.sleep for some secs.

I'm using the latest 1.2.1.0 sdk to test. and Splunk 6 + max osx

Tags (1)
0 Karma

Damien_Dallimor
Ultra Champion
0 Karma

preben12
Communicator

Hi Damien
That looks doable, but with a couple of pitfalls since loops that contain Thread.sleeps have to be guarded by the possibility to break the loop when you want to stop the search thread from outside.

Somehow I feel that the SDK should take care of this eg. by fixing the isReady method so it returns when the stream is ready (there is at least 1 preview event, or there is no events in the current time window).

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...