[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

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!
0
snajalm
Asked:
snajalm
1 Solution
 
DataCruncherCommented:
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.
0
 
mlempertCommented:
Some databases include triggers which will perform an action when a table row is inserted or updated.  This might work better for you if the polling method that DataCruncher does not work for you.
0
 
gordon_vt02Commented:
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.
0
 
snajalmAuthor Commented:
Thanks!
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now