---
title: "Ruby中监控文件系统的变化"
author: "cnetwei"
date: "2012-12-26T19:31:55Z"
tags: []
categories: ["编程语言"]
slug: "ruby"
draft: false
lastmod: "2012-12-26T19:31:55Z"
id: 1754643
url: "https://cnetwei.iteye.com/blog/1754643"
---

JRuby中监控文件系统的变化

 

Ruby平台有两个gem包可用于监听文件系统变化：[fssm](https://github.com/ttilley/fssm) 和 [listen](https://github.com/guard/listen)。

 

fssm当前似乎不能运行在JRuby平台上，listen可以在JRuby上运行，但它降级采用了轮询检查的模式，性能变低。

事实上在JDK 7中有一个新的特性：[The Watch Service API](http://docs.oracle.com/javase/tutorial/essential/io/notification.html) 正好可用于此，有机会的话希望能对listen进行改进，以支持在JRuby下使用The Watch Service API。

 

 

参考资料：

[Java 7 NIO.2 入门](http://www.ibm.com/developerworks/cn/java/j-nio2-2/index.html)

[Java 7 NIO.2 文件监视服务简介](http://www.ibm.com/developerworks/cn/java/j-nio2-2/index.html?ca=dat)

[通过Java SE 7自带的监控服务（WatchService API）实现类似.NET FileWatcher的功能](http://www.cnblogs.com/callwangxiang/archive/2011/08/04/JavaDirectoryWatcherFileWatcher.html)