# When Java's WatchService is not the right tool in a container

DevFeed: [When Java's WatchService is not the right tool in a container](<https://devfeed.tech/articles/when-java-s-watchservice-is-not-the-right-tool-in-a-container-26071.md>)

Original publisher: [Read original article](<https://blog.arkey.fr/2019/09/13/watchservice-and-bind-mount/>)

Author: brice.dutheil@gmail.com (Brice Dutheil)

Published: 2019-09-13T00:00:00Z

Content type: tutorial

Language: en

Sources: [The Coffee Workshop](<https://devfeed.tech/sources/the-coffee-workshop.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [container](<https://devfeed.tech/topics/container.md>), [Filesystems](<https://devfeed.tech/topics/filesystems.md>), [Linux](<https://devfeed.tech/topics/linux.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [container](<https://devfeed.tech/tags/container.md>), [development](<https://devfeed.tech/tags/development.md>), [java](<https://devfeed.tech/tags/java.md>), [linux](<https://devfeed.tech/tags/linux.md>), [tests](<https://devfeed.tech/tags/tests.md>)

## AI overview

This tutorial examines why Java's WatchService can behave differently inside a Linux container than on a physical machine. It explains platform-specific filesystem event implementations and investigates the container-related cause using Linux filesystem monitoring tools.

## Source excerpt

Boring code that should be written once and run everywhere Suppose the application you're working on needs to monitor changes to a file and rely on Java's WatchService introduced in Java 7. Development and test on the local machine works ; the unit tests rely on a TemporaryFolder Junit rule as you want to control the content of the file, running the code on the actual machine just works as expected. Everything is green to go live.