<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Develop a Java File Watcher</title>
	<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/</link>
	<description>Good judgement comes from experience, and experience comes from bad judgement.</description>
	<pubDate>Tue, 06 Jan 2009 01:34:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Suman K</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-31922</link>
		<dc:creator>Suman K</dc:creator>
		<pubDate>Tue, 09 Dec 2008 16:55:52 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-31922</guid>
		<description>Oljas,

Add the following in the end of the takeSnapshot() function:

Runtime runtime = Runtime.getRuntime();
runtime.gc();

This should solve the memory leak problem.</description>
		<content:encoded><![CDATA[<p>Oljas,</p>
<p>Add the following in the end of the takeSnapshot() function:</p>
<p>Runtime runtime = Runtime.getRuntime();<br />
runtime.gc();</p>
<p>This should solve the memory leak problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nitin Gupta</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-29988</link>
		<dc:creator>Nitin Gupta</dc:creator>
		<pubDate>Mon, 24 Nov 2008 10:46:27 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-29988</guid>
		<description>Hi, Can you please explain me how can i use this code?

Thanks
Nitin</description>
		<content:encoded><![CDATA[<p>Hi, Can you please explain me how can i use this code?</p>
<p>Thanks<br />
Nitin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oljas</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-21115</link>
		<dc:creator>Oljas</dc:creator>
		<pubDate>Tue, 07 Oct 2008 10:28:47 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-21115</guid>
		<description>Hi everyone.
I try to use this program.
I run it and open TaskManager on XP too.
So, the resource size this program is using is growing up, each second(or 2-3 seconds) its growing for some bytes ... thats because i can't use it(after some time my computer won't have any resource to use it). Is there any way to solve this program?</description>
		<content:encoded><![CDATA[<p>Hi everyone.<br />
I try to use this program.<br />
I run it and open TaskManager on XP too.<br />
So, the resource size this program is using is growing up, each second(or 2-3 seconds) its growing for some bytes &#8230; thats because i can&#8217;t use it(after some time my computer won&#8217;t have any resource to use it). Is there any way to solve this program?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vamsi krishna</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-12153</link>
		<dc:creator>vamsi krishna</dc:creator>
		<pubDate>Wed, 16 Jul 2008 09:32:00 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-12153</guid>
		<description>hi thanks for this code i am looking for the same functionality in java.</description>
		<content:encoded><![CDATA[<p>hi thanks for this code i am looking for the same functionality in java.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kyle</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-7198</link>
		<dc:creator>kyle</dc:creator>
		<pubDate>Fri, 02 May 2008 21:43:34 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-7198</guid>
		<description>Instead of a directory, I want to watch a table inside a database for entries, and the call the appropriate methods to handle the records.  Basically the requirement is:
if the timestamp on a particular row is greater then 4 minutes, meaning its not been processed, then it should send a message to group list notifying them of this condition.</description>
		<content:encoded><![CDATA[<p>Instead of a directory, I want to watch a table inside a database for entries, and the call the appropriate methods to handle the records.  Basically the requirement is:<br />
if the timestamp on a particular row is greater then 4 minutes, meaning its not been processed, then it should send a message to group list notifying them of this condition.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sudhakar</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-6412</link>
		<dc:creator>sudhakar</dc:creator>
		<pubDate>Tue, 22 Apr 2008 07:36:46 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-6412</guid>
		<description>this DirectoryWatcher applicaton is almost similar to our requirements.with this code it shows only modified or added or deleted filenames when ever you updated the directory. but in our requirement, basically directory contains number of log files and  not only monitering the directory i need to parse the content of a modified or new log file and pick the required information from that log file.

can anybody help me out please? this is urgent requirement...</description>
		<content:encoded><![CDATA[<p>this DirectoryWatcher applicaton is almost similar to our requirements.with this code it shows only modified or added or deleted filenames when ever you updated the directory. but in our requirement, basically directory contains number of log files and  not only monitering the directory i need to parse the content of a modified or new log file and pick the required information from that log file.</p>
<p>can anybody help me out please? this is urgent requirement&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: iLenceel&#187; Blog 存档 &#187; links for 2007-10-09</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-1257</link>
		<dc:creator>iLenceel&#187; Blog 存档 &#187; links for 2007-10-09</dc:creator>
		<pubDate>Thu, 29 Nov 2007 03:03:29 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-1257</guid>
		<description>[...] Develop a Java File Watcher [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Develop a Java File Watcher [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Miller</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-51</link>
		<dc:creator>Alex Miller</dc:creator>
		<pubDate>Wed, 03 Oct 2007 14:15:00 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-51</guid>
		<description>BTW, support for file (or directory) watching is included in JSR 203 (the new new Java I/O API) which should be part of Java 7.  More info on my Java 7 page &lt;a href="http://tech.puredanger.com/java7#jsr203" rel="nofollow"&gt;here&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>BTW, support for file (or directory) watching is included in JSR 203 (the new new Java I/O API) which should be part of Java 7.  More info on my Java 7 page <a href="http://tech.puredanger.com/java7#jsr203" rel="nofollow">here</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: GuidoLx</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-50</link>
		<dc:creator>GuidoLx</dc:creator>
		<pubDate>Wed, 03 Oct 2007 11:28:42 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-50</guid>
		<description>There is just one thing I don't like in your design.
Whenever you are doing file-related operations, use the java.io.File object and do not use a java.lang.String!
My 2c,

Guido</description>
		<content:encoded><![CDATA[<p>There is just one thing I don&#8217;t like in your design.<br />
Whenever you are doing file-related operations, use the java.io.File object and do not use a java.lang.String!<br />
My 2c,</p>
<p>Guido</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: timber</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-49</link>
		<dc:creator>timber</dc:creator>
		<pubDate>Wed, 03 Oct 2007 08:01:45 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-49</guid>
		<description>There is always this project on sourceforge. Not used it though.

http://jpoller.sourceforge.net/</description>
		<content:encoded><![CDATA[<p>There is always this project on sourceforge. Not used it though.</p>
<p><a href="http://jpoller.sourceforge.net/" rel="nofollow">http://jpoller.sourceforge.net/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sander</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-48</link>
		<dc:creator>Sander</dc:creator>
		<pubDate>Wed, 03 Oct 2007 04:18:11 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-48</guid>
		<description>Why are you calling yourself ThoughtWorks? Do you have anything to do with www.thoughtworks.com?</description>
		<content:encoded><![CDATA[<p>Why are you calling yourself ThoughtWorks? Do you have anything to do with <a href="http://www.thoughtworks.com?" rel="nofollow">http://www.thoughtworks.com?</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thoughtworks</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-46</link>
		<dc:creator>thoughtworks</dc:creator>
		<pubDate>Wed, 03 Oct 2007 02:17:33 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-46</guid>
		<description>Jason, 

I faced the some problem as what you encountered also. I resolved it using 2 ways.

1. 1st way is similar to what you did, I monitor the file size/modified date and if the file size/modified date are not the same during an interval, then I will keep on waiting.

2. Another way to resolve the large file issue is to monitor on dummy file with empty content. E.g. copying a large file to directory A and once it is done, create a dummy file in directory B, and monitoring is only only directory B. Of course this depends on the program pushing the file to create another dummy file once the upload/copying is completed.

Rob,
I need it on Unix/Linux platform. Let me know if you have a similiar solution on Unix/Linux platform.

Thanks</description>
		<content:encoded><![CDATA[<p>Jason, </p>
<p>I faced the some problem as what you encountered also. I resolved it using 2 ways.</p>
<p>1. 1st way is similar to what you did, I monitor the file size/modified date and if the file size/modified date are not the same during an interval, then I will keep on waiting.</p>
<p>2. Another way to resolve the large file issue is to monitor on dummy file with empty content. E.g. copying a large file to directory A and once it is done, create a dummy file in directory B, and monitoring is only only directory B. Of course this depends on the program pushing the file to create another dummy file once the upload/copying is completed.</p>
<p>Rob,<br />
I need it on Unix/Linux platform. Let me know if you have a similiar solution on Unix/Linux platform.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Wall</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-45</link>
		<dc:creator>Tim Wall</dc:creator>
		<pubDate>Tue, 02 Oct 2007 20:55:22 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-45</guid>
		<description>The polling approach has a number of drawbacks that rapidly become apparent as the number of 'watched' files increases.  It's better to rely on an OS-provided service for this sort of thing.

You'll find that the underlying 'stat' triggered by many of java.io.File methods can quickly become a performance bottleneck.

So polling is not a bad solution if you're looking at one or two files, but I wouldn't recommend it for an IDE tracking external changes to a project's files.</description>
		<content:encoded><![CDATA[<p>The polling approach has a number of drawbacks that rapidly become apparent as the number of &#8216;watched&#8217; files increases.  It&#8217;s better to rely on an OS-provided service for this sort of thing.</p>
<p>You&#8217;ll find that the underlying &#8217;stat&#8217; triggered by many of java.io.File methods can quickly become a performance bottleneck.</p>
<p>So polling is not a bad solution if you&#8217;re looking at one or two files, but I wouldn&#8217;t recommend it for an IDE tracking external changes to a project&#8217;s files.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Di Marco</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-44</link>
		<dc:creator>Rob Di Marco</dc:creator>
		<pubDate>Tue, 02 Oct 2007 19:49:54 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-44</guid>
		<description>Another implementation is available using the Java Native Access API.  You can see an example FileMonitor at:

https://jna.dev.java.net/source/browse/
jna/trunk/jnalib/src/com/sun/jna/examples/
FileMonitor.java?rev=HEAD&#38;view=markup</description>
		<content:encoded><![CDATA[<p>Another implementation is available using the Java Native Access API.  You can see an example FileMonitor at:</p>
<p><a href="https://jna.dev.java.net/source/browse/" rel="nofollow">https://jna.dev.java.net/source/browse/</a><br />
jna/trunk/jnalib/src/com/sun/jna/examples/<br />
FileMonitor.java?rev=HEAD&amp;view=markup</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Daggs</title>
		<link>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-43</link>
		<dc:creator>Jason Daggs</dc:creator>
		<pubDate>Tue, 02 Oct 2007 17:25:32 +0000</pubDate>
		<guid>http://twit88.com/blog/2007/10/02/develop-a-java-file-watcher/#comment-43</guid>
		<description>This was the initial approach I tried on several occasions.   However, one problem I ran into was that even though the file name shows up in the directory list the file itself may not actually exist on the file system.  Let me explain.  If I copy a large file from a remote network source to the local directory being monitored, that file will still show up in the directory listing, but before the network copy has completed.  If I try to do almost anything non trivial to the file at that moment like move it to another directory or open it for writing, an exception will be thrown because really the file is not yet completely there and the OS still has a write lock on it.  So, what I did was perform a test on each new file before I raised the "file ready" event.   I opened up a FileIputStream on the file if a FileNotFoundException is thrown then  sleep a few seconds and then keep trying( bit forever but you get the picture) If no exception is thrown the the file is ready.(tested on windows not yet on linux)  This approach will not solve all issues of course, but did allow us to implement a very robust approach to file system monitoring.  Of course,  IMHO avoiding directory monitoring whenever possible would be my preferred approach.</description>
		<content:encoded><![CDATA[<p>This was the initial approach I tried on several occasions.   However, one problem I ran into was that even though the file name shows up in the directory list the file itself may not actually exist on the file system.  Let me explain.  If I copy a large file from a remote network source to the local directory being monitored, that file will still show up in the directory listing, but before the network copy has completed.  If I try to do almost anything non trivial to the file at that moment like move it to another directory or open it for writing, an exception will be thrown because really the file is not yet completely there and the OS still has a write lock on it.  So, what I did was perform a test on each new file before I raised the &#8220;file ready&#8221; event.   I opened up a FileIputStream on the file if a FileNotFoundException is thrown then  sleep a few seconds and then keep trying( bit forever but you get the picture) If no exception is thrown the the file is ready.(tested on windows not yet on linux)  This approach will not solve all issues of course, but did allow us to implement a very robust approach to file system monitoring.  Of course,  IMHO avoiding directory monitoring whenever possible would be my preferred approach.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
