Solved

Knowing when a file writting has ended

Posted on 2000-05-09
6
181 Views
Last Modified: 2013-12-16
Hi,

I am writting to a file, from a java application.
The file is big so multiple flush will occur during the writting. That file will be used by another application(Cold Fusion), that will read it and do it's job. What I need is a way of letting the ColdFusion alllication know that the writting to the file has finished and the file is ready for use.
I know I could read the file from ColdFusion and check for something at the end that will tell me the file is OK, but the file is big. I am looking for some suggestions.
Thanks.
0
Comment
Question by:simi
6 Comments
 
LVL 4

Expert Comment

by:adam923
ID: 2794308
how about creating a second file as a "flag" to coldfusion?
so at the end of your large file write activity you could just write another tiny file... meanwhile coldfusion could wait in a loop until that "flag" file exists
0
 

Author Comment

by:simi
ID: 2794334
That's one of the solutions I had in mind, together with another one that is, reading the date when the big file is created, then loop reading the date untill it changed(I have tested writting the file from a java application and the date is changed only when I close the stream to the file. Flushing the buffer does not change the date, even if it does write to the file.
Sorry, I should have posted all that from the begining.
So what I am looking for is if someone has some other solution that would work better, or if someone can see some problems with the ones I have allready presented.
Thanks.
0
 
LVL 4

Expert Comment

by:adam923
ID: 2794434
what don't you like about that solution?  
i don't know what kind of support for sockets cold fusion has but you could open a socket between the two apps to communicate
files and sockets are the most common ways of communicating between processes... although i'm sure there are others as well
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:simi
ID: 2794594
Is not something that I particulary don't like, but more that the project manager was suggesting of a more elegant solution, and I wanted to see if there are any ideeas.

I can't use sockets now, it'll have to be a file that I read.
Thanks anyway.
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2796339
What is the relationship between the ColdFusion application and the Java application?

If the ColdFusion app is the parent of the Java app and it tells its child process the name of the file to write, perhaps you could do something like write to a temporary filename from the Java app and then rename to the agreed upon final file when done. The ColdFusion app could wait until the name file appears at which point it would be complete. The hole in this is, what to do if something catastrophic occurs to the Java app and the file never appears? Can the ColdFusion app know when its child terminates? Using this indication along with or instead of the temporary file scheme could round out the solution.

Best regards,
Jim Cakalic
0
 
LVL 9

Accepted Solution

by:
Dain_Anderson earned 50 total points
ID: 2830974
Here is a very simple technique to see if the file is in use. By trying to rename the file, you will get an error since the file is being written to, at which point it is read-only.

So, in ColdFusion, use:

<CFTRY>
    <CFFILE ACTION="Rename"
        SOURCE="d:\myFile1.txt"
        DESTINATION="d:\myFile2.txt">
    <CFFILE ACTION="Rename"
        SOURCE="d:\myFile2.txt"
        DESTINATION="d:\myFile1.txt">
    <CFCATCH TYPE="Any">
        <CFOUTPUT>#CFCATCH.detail#</CFOUTPUT>
        File is in use -- try again later.
    </CFCATCH>
</CFTRY>

This takes exactly 4 milliseconds to process, so you can see it's quite efficient.

Hope that helps
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 82
even odd program using while loop 3 60
servlet example 11 49
ejb message driven bean mdb creation steps 2 18
Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

840 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