[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

Real Time Analysis

Hello,
I have a java simulation program which presents 75 records of data every 15 seconds. It then pauses for "x" seconds. And presents another 75 seconds of data, and so on... All this data is written to a data file "abc.dat".

Could somebody tell me how to analyze this file in real-time depending on when new data is available in the file "abc.dat"? I would like to do it preferably in Java. The analysis program should check "abc.dat" on regular intervals of time or a user defined interval of time.

Any help on this issue would be appreciated.

Thank you,
AS
0
singhanupam
Asked:
singhanupam
1 Solution
 
GuntCommented:
You can start a timer that checks if the file timestamp changes every X amount of time (depending on your required level of granularity).

A good implementation of this, using the observer pattern can be found here http://www.rgagnon.com/javadetails/java-0214.html

Check the DataFileWatchDog class by the end of the page.
0
 
JohnnyAffaCommented:
how much java do you know?
do you know about threads?  
do you know about files?
how and who is modifiying the abc.dat file?
how often will it need to be checked?
0
 
singhanupamAuthor Commented:
I have been using Java as a programming tool for my simulations. I could have used Fortran too, but I wanted to use Java instead. Lets see, I know a little about threads, but I have been using file handling efficiently.

The "abc.dat" is being created by my simulation tool which I have created in Java. 75 records are written to this file, then the program pauses for 15 seconds and then another 75 records are written and so on... Each record has a time stamp in increments of .25seconds.

The analysis file should check this "abc.dat" file based on user inputs. For example if the user specifies that he/she wants a 10second refresh rate, it should analyze all the precious data already in the file plus the latest 10 seconds of data. I hope I was able to explain the problem.

Thank you
0
 
gen718Commented:
Use 2 threads; one thread to generate the data to be analyzed and the other to do the analysys. Use a work queue to pass data between them in some "Work" object. You can trigger the analysis thread to perform the analysis via a "Analyze" work object. The analysis thread caches the records and/or writes them to file.

The "Analyze" work object can be posted to the queue when you finish creating the 75 records or when the user specifies.

The analysis thread can reread the file if you wish or analyze the cache of records whenever it receives the "Analyze" work object trigger. An implementation of a thread-safe work queue can be found in Chan's Java Almanac Volume 1.

The "Analyze" work object can be derived from a generic "Work" object or simply implemented as a flag in the generic "Work" object. Up to you.

Just some thoughts on a possible implementation. As always, there are many possible solutions.

Hope this helps a bit :)


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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