Real Time Analysis

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,
Who is Participating?

Improve company productivity with a Business Account.Sign Up

GuntConnect With a Mentor Commented:
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

Check the DataFileWatchDog class by the end of the page.
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?
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
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 :)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.