Link to home
Start Free TrialLog in
Avatar of snajalm
snajalm

asked on

Java DB checking against Date/Time fields (event handling)?

How can I come up with a mechanism in java where I could monitor the date/time fields inside a Java DB table and as soon as the the date/time fields for one or many of the records match the system time I could grab them for further processing??!  Sample code would be appreciated!
Avatar of DataCruncher
DataCruncher
Flag of Canada image

Hi, I think a little more details could help, is it something like:

- Process A inserts records in the Java DB database, one of the table fields being a DATETIME
- Process B watch that same table at a given interval of time (1 minute) to see if there are any records where DATETIME = now

When you say "matching the system date", you mean to the second, minute, hour or day?
Also, if process A and B in your system are within the same application, there might be better way for process B to be notified that there are records to be processed.
ASKER CERTIFIED SOLUTION
Avatar of mlempert
mlempert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gordon_vt02
gordon_vt02

Another option would be to load any rows that will occur within the next time period, T, and use a scheduled executor to start processes for those rows when they should occur.  You could then run the polling process after T has elapsed (or with some lead time to make sure anything that happens at T+0 is processed correctly).  The only difficulty with this approach is detecting any changes to the underlying database.  Triggers are a much safer way to go, but that's only if you can put all the logic in the database itself.

Example:

Schedule a process that runs at the 50th minute of every hour.  This process runs the query:

SELECT * FROM db_table WHERE time BETWEEN next_hour AND next_hour+one_hour;

The returned items are then added to a scheduled processing queue (see java.util.concurrent API docs) and set up to run at their corresponding time.
Avatar of snajalm

ASKER

Thanks!