<p><strong>Story</strong>: in my java code i have a few ScheduledFuture's that i need to run everyday on specific time (15:00 for example), the only available thing that i have is database, my current application and openshift with multiple pods. I can't move this code out of my application and must run it from there.</p>
<p><strong>Problem</strong>: ScheduledFuture works on every pod, but i need to run it only once a day. I have a few ideas, but i don't know how to implement them.</p>
<p><strong>Idea #1</strong>:
Set environment variable to specific pod, then i will be able to check if this variable exists (and its value), read it and run schedule task if required. I know that i have a risk of hovered pods, but that's better not to run scheduled task at all than to run it multiple times.</p>
<p><strong>Idea #2</strong>:
Determine a leader pod somehow, this seems to be a bad idea in my case since it always have &quot;split-brain&quot; problem.</p>
<p><strong>Idea #3 (a bit offtopic)</strong>:
Create my own synchronization algorithm thru database. To be fair, it's the simplest way to me since i'm a programmer and not SRE. I understand that this is not the best one tho.</p>
<p><strong>Idea #4 (a bit offtopic)</strong>:
Just use quartz schedule library. I personally don't really like that and would prefer one of the first two ideas (if i will able to implement them), but at the moment it seems like my only valid choice.</p>
<p>UPD. May be you have some other suggestions or a warning that i shouldn't ever do that?</p>

<p>I would suggest to use a ready-to-use solution. Getting those things right, especially covering all possible corner-cases wrt. reliability, is hard. If you do not want to use quartz, I would at least suggest to use a database-backed solution. Postgres, for example, has <a href="https://www.postgresql.org/docs/current/sql-select.html" rel="nofollow noreferrer"><code>SELECT ... FOR UPDATE SKIP LOCKED;</code> (scroll down to the section &quot;The Locking Clause&quot;)</a> which may be used to implement one-time only scheduling.</p>
