# Scheduler Java plugin Logstash

**URL:** <https://discuss.elastic.co/t/scheduler-java-plugin-logstash/297482>\
**Category:** Logstash\
**Created:** [February 17, 2022, 11:30am UTC](https://discuss.elastic.co/t/scheduler-java-plugin-logstash/297482 "2022-02-17T11:30:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aalagia](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@aalagia](https://discuss.elastic.co/u/aalagia)\
**Post date:** [February 17, 2022, 11:30am UTC](https://discuss.elastic.co/t/scheduler-java-plugin-logstash/297482/1 "2022-02-17T11:30:19Z")

</div>

Hi,  
I need to use scheduler in custom plugin written in Java for Logstash. How is possible to implement this thing?

Thank you  
Antonio

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [February 17, 2022, 1:33pm UTC](https://discuss.elastic.co/t/scheduler-java-plugin-logstash/297482/2 "2022-02-17T13:33:57Z")

</div>

Schedule is a plugin option, if the custom plugin has an option to schedule, then you can use it, if it has not, then there is nothing in Logstash that does that, you would need to schedule the Logstash service itself.

---

<div class="post-metadata">

**Author:** ![aalagia](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@aalagia](https://discuss.elastic.co/u/aalagia)\
**Post date:** [February 17, 2022, 1:36pm UTC](https://discuss.elastic.co/t/scheduler-java-plugin-logstash/297482/3 "2022-02-17T13:36:40Z")

</div>

I tried to use the Java Timer for this but doesn't work. The pipeline execute the code but termite after few seconds.

```auto
 @Override
    public void start(Consumer<Map<String, Object>> consumer) {

        // The start method should push Map<String, Object> instances to the supplied QueueWriter
        // instance. Those will be converted to Event instances later in the Logstash event
        // processing pipeline.
        //
        // Inputs that operate on unbounded streams of data or that poll indefinitely for new
        // events should loop indefinitely until they receive a stop request. Inputs that produce
        // a finite sequence of events should loop until that sequence is exhausted or until they
        // receive a stop request, whichever comes first.
        
        
        Timer timer = new Timer("Logstash Plugin");
        timer.scheduleAtFixedRate(mymethod, 0L, 300000);
     
    }

```

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [February 17, 2022, 1:42pm UTC](https://discuss.elastic.co/t/scheduler-java-plugin-logstash/297482/4 "2022-02-17T13:42:53Z")

</div>

This is more a Java development question than a Logstash one, you need to look how to implement a schedule on a Java code.

You could look at the code of some plugins that have schedule, like the `jdbc` input, to see how it is done, but I don't think it will be much help because they are written in Ruby.

---

<div class="post-metadata">

**Author:** ![aalagia](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@aalagia](https://discuss.elastic.co/u/aalagia)\
**Post date:** [February 17, 2022, 1:46pm UTC](https://discuss.elastic.co/t/scheduler-java-plugin-logstash/297482/5 "2022-02-17T13:46:47Z")

</div>

Thank you for the answers, but i know how to implement a schedule in Java but this doesn't work when i create the plugin logstash and i lanuch the pipeline.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [February 17, 2022, 2:02pm UTC](https://discuss.elastic.co/t/scheduler-java-plugin-logstash/297482/6 "2022-02-17T14:02:21Z")

</div>

What kind of plugin it is, input, codec, filter or output?

I'm not sure if an Schedule would be supported anywhere else besides the **input**.

Maybe in your case it would be better to open an issue in the [respective repo](https://www.elastic.co/guide/en/logstash/current/contributing-java-plugin.html#_lets_get_started).

---

<div class="post-metadata">

**Author:** ![aalagia](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@aalagia](https://discuss.elastic.co/u/aalagia)\
**Post date:** [February 17, 2022, 2:07pm UTC](https://discuss.elastic.co/t/scheduler-java-plugin-logstash/297482/7 "2022-02-17T14:07:42Z")

</div>

The plugin i have written is input. I try to open an issue. Thank you

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 17, 2022, 2:08pm UTC](https://discuss.elastic.co/t/scheduler-java-plugin-logstash/297482/8 "2022-03-17T14:08:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
