Questions tagged [watchservice]

WatchService is a Java API for watching changes on a filesystem. It was introduced in Java 7.

WatchService is a Java API for monitoring file systems for changes. It can be used to detect new files, modified files or file deletions. It was introduced in Java 7 and is part of the (new) NIO system.

223 questions
5
votes
1 answer

WatchService (Windows 7): when deleting a file, it fires both ENTRY_MODIFY and ENTRY_DELETE events?

In working with the WatchService, I found that if I delete a file in the directory being watched, it fires an ENTRY_MODIFY followed by an ENTRY_DELETE event. I realize that technically, a file may be modified before deleted, but is it really the…
Sam Goldberg
  • 6,711
  • 8
  • 52
  • 85
5
votes
0 answers

File.exists() is not accurate on smb2 network share (use WatchService?)

According to this document: http://technet.microsoft.com/en-us/library/ff686200%28v=ws.10%29.aspx File.exists() is not accurate on a smb2 network share. I am not able to change any register settings, so I want to deal with it. According to the…
Olaf
  • 146
  • 8
5
votes
1 answer

How to stop Java WatchService when is waiting for key?

I'm trying to stop my thread where WatchService is working. But how to do that? My WatchService waiting for new update in folder there: key = watchService.take(); I start my Thread there: private void startButtonActionPerformed(ActionEvent e) { …
Boris Mitioglov
  • 1,092
  • 4
  • 16
  • 32
5
votes
1 answer

Determining type of deleted file from WatchEvent

I have a WatchService that watches a directory tree for ENTRY_CREATE, ENTRY_DELETE AND ENTRY-MODIFY events. The problem is that the context of a WatchEvent gives only a Path object. On delete events, I'm unsure of if the path referred to a…
efritz
  • 5,125
  • 4
  • 24
  • 33
5
votes
0 answers

Java 7 WatchService does not generate events when registered directory is on a network drive

I know this was asked elsewhere a year ago but I'm looking for any updates please. I have a program in Java 7 that uses WatchService to monitor a directory for new files being created there. If I register a directory on my local machine (e.g.…
FlexMcMurphy
  • 420
  • 5
  • 21
5
votes
2 answers

Releasing resources of Java 7 WatchService

I am using Java 7 WatchService to watch directories. I constantly change which directories i am watching. I run into the exception: java.io.IOException: The network BIOS command limit has been reached. after 50 directories. I am certain i call…
Dave
  • 108
  • 1
  • 8
4
votes
2 answers

Java 7 WatchService: avoiding an infinite loop of events when changing the event source in handler

Basically, I'm using the fresh new Java's 7 WatchService to monitor a directory. I have a chain of handlers listening to every IO event issued by the directory. The problem is some of the handlers need to change the reason of those IO events (==…
4
votes
2 answers

Restart WatchService after exceptions

I'm using Java's WatchService API within my Spring Boot application to monitor a directory, and perform some actions on created files. This process is executed asynchronously: it starts automatically right after the application is ready and monitors…
thmasker
  • 406
  • 1
  • 9
  • 21
4
votes
0 answers

How many directories can Java WatchService listen to at the same time?

Is this OS related, or there is some limitation in Java that I should be aware of? fs.inotify.max_user_watches = 524288
yuyang
  • 1,511
  • 2
  • 15
  • 40
4
votes
0 answers

Can you prevent WatchService from Locking files on Windows?

In Java, if you use the WatchService frameworks to watch the disk for changes, it locks the parents of watched directories, preventing deletion, renaming, etc. This is an undesirable behavior for my program. Is it possible to either tell the…
Grumblesaurus
  • 3,021
  • 3
  • 31
  • 61
4
votes
2 answers

How do I unregister a directory from Java watchservice?

I registered a folder to my watchService: path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); Later on, I want to cancel this registration. I know that I somehow need to tell the watchService which WatchKey I want to cancel.…
Bowueewa
  • 53
  • 1
  • 3
4
votes
1 answer

WatchService uses 100% of CPU on CentOS

I am using a WatchService in my application. When I run my application on a Windows environment, the application uses less than 1% of the CPU. When the same application is run on my Linux server, it uses 100% of the CPU. When the WatchService thread…
noahnu
  • 3,479
  • 2
  • 18
  • 40
4
votes
1 answer

Why does WatchService use unbound wildcard WatchEvent rather than WatchEvent

I just followed this tutorial to use the WatchService API. I have no idea about why using WatchEvent rather than WatchEvent, if I use the latter one, no need to cast, or there is any other situations that the WatchService can use to…
jaychang0917
  • 1,880
  • 1
  • 16
  • 21
4
votes
2 answers

WatchService WatchEvent .context() method returns inconsistent relative path for file on ENTRY_MODIFY (goutputstream-####, Linux OS)

In this code, I'm hoping to update a HashMap with the most recent version of a given path's contents, with the absolute path as string being used as the key. The problem is that WatchEvent's .context() method is giving me a different relative path…
Mer
  • 762
  • 1
  • 6
  • 12
4
votes
2 answers

What does it mean for an event to be "repeated?"

Reading the javadocs for WatchEvent, I see that the count() method lets me know if an event is repeated by its result. Returns the event count. If the event count is greater than 1 then this is a repeated event. What does that mean, exactly? Does…
2rs2ts
  • 10,662
  • 10
  • 51
  • 95
1 2
3
14 15