开发者

Java long task - Did it stop writing to file?

开发者 https://www.devze.com 2022-12-23 06:41 出处:网络
I am writing a lot of data to a file, and while keeping my eye on the file it eventually stopped growing in size.

I am writing a lot of data to a file, and while keeping my eye on the file it eventually stopped growing in size.

Essentially my task is getting information from a database, and printing out ALL values in column A - despite if they are duplicate values or not...

Since there are many rows to the database table, and the database table is across my network, this is taking days to complete. Thus I'm concerned that since the file isn't growing, that it isn't actually writing to the file anymore.

-- Which is odd, I have no "catch"'s in my code, so if there was a problem writing to file, wouldn't it have thrown an error?!

Should I let the task complete (estimate 2-3 days from today), or is there something else that I don't know going on here making my application not write to the file?!

my algorithm goes something like this

Declare file
Create new file
Open file for writing (using bufferedwriter)
get database connection
get resultset from database
for each row in the resultset 
   - write column "A" to file
   - if row# % 100000 then write to screen "completed " + row# + " rows"
when 开发者_StackOverflow社区no more rows exist
close file
write to screen - "completed"

(using windows 7)


Did you try the stream.flush() method? (which will be called at least via stream.close())

-> so try flush 'regularly' and see if that helps.

WARNING: If you are flushing too frequently you will have performance losts

E.g. try

if rowNumber % 100000 then flush


Its possible you have encountered a section of your db where there are no duplicates, the query has stopped responding (or timed-out) or a number of other conclusions. There is not enough data in your question to really answer.

A couple of suggestions:

  1. Divide the task of finding duplicates up (do you have unique row identifiers in the db perhaps). This will allow you to judge how long is left and let you know in byte size chunks when each step is done
  2. Add Logging. Lots of logging, report whats going on and when you did it. Log to the screen at least, then you just have to watch for movement on the screen
  3. If the data coming out is large write to more than one file. Write chunks to files so you can work with the chunks while your waiting
  4. Try and optimize that query to reduce the runtime, or predetermine the results (to a temp table) and then execute on that if possible. It will make it easier to resume if there is a failure.


You included no details about your OS. Depending on the OS, there are ways to determine the open files for a process (On UNIX try: lsof), or vice-versa, the process that is using a file (UNIX: fuser).

I also note that you said "/n" in your example, hopefully you meant "\n". Backslash is the proper escape for newline. If not, that could be an issue since IO layers often don't flush until a newline is seen or a buffer fills. For this reason, consider WriteLine() instead of Write(), or call flush as another suggested.

EDIT: For Windows try Process Explorer: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号