Solved

Real Time Analysis

Posted on 2004-09-04
4
265 Views
Last Modified: 2010-05-18
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
Comment
Question by:singhanupam
4 Comments
 
LVL 3

Accepted Solution

by:
Gunt earned 500 total points
ID: 11980946
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
 
LVL 3

Expert Comment

by:JohnnyAffa
ID: 11984134
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
 

Author Comment

by:singhanupam
ID: 11989838
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
 
LVL 2

Expert Comment

by:gen718
ID: 12036999
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now