I need to have a Java method run every 30 seconds within a WebSphere 7 clustered environment (two boxes with 1 server each) - what's the current best-practice to do this while avoiding concurrency issues?
Some more details: We've got records in an Oracle database that need to be twiddled exactly once. If they get double-twiddled, bad things will happen.
So I'm imagining something like this:
public synchronized void BatchTwiddle() {
List myList = findRecordsToBeTwiddled();
twiddleRecords(myList);
}
public void twiddleRecords(myRecords myList) {
ListIterator<myRecord> myRecordsIterator = myList.listIterator();
while (myRecordsIterator.hasNext()) {
myRecordsIterator.next().twiddleRecord();
}
}
How do I get BatchTwiddle() called every thirty seconds when there's multiple servers (A total of 2) involved? Is it best to just run it on ONE server
So far, I've been digging into the WebSphere Scheduler concept, using ScheduledExecutorService, or using EJB Timers, but nothing seems like a clear winner yet.