Java Advanced Applications (one)-Folder monitoring service

Source: Internet
Author: User

Recent. In the study of some more mature frameworks. They also found some of them quite good articles. Now, for some of you in the middle of a simple translation ( version of the English article, very helpful ).

Translation: Original link

did you ever find that when you edit a file. At the same time, when using an IDE or editor for editing, a dialog box informs "that an open file has changed, does it need to be loaded again?" ”。 But some applications like NetBeans IDE just silently update the file without notifying you.

To implement this "file monitoring" feature, the program must be able to detect what is happening in the file system-related folders. One way is to check what happens to the file system. But such an approach is inefficient. It cannot monitor open files or folders on a large scale. Another way is to use the Java.nio.file package to provide a file monitoring service. This service agrees to monitor your service for a folder or multiple folders.

At the time of registration. Just need to tell the events that need to be monitored, including the creation, deletion, and alteration of files. When the service monitors the corresponding event, it runs the event of the registration. The event in the register will have a thread or pool of threads to monitor the events that have been registered, so that when a register event occurs, it will be processed accordingly.

file Folder monitoring service Watchservice is easy to use and you can even define it yourself. You can use it directly or extend it on top of the original to make it more suitable for your particular needs.

The basic process for creating a folder monitoring service is as follows:
1, create a file system monitoring service-watchservice.
2, in the file system monitoring service to register you need to monitor the file folder. When you register a folder. Specifies the type of monitoring.
3, write an infinite wait. An event method that monitors the occurrence of an event. In order to be able to respond and terminate immediately after the event that the folder in the queue is monitored for response.


4, the whole monitoring process is the key. Ability to get the monitored file name from the monitoring key provided by the monitoring service
5, monitoring to wait for the occurrence of the key is to be able to run the required process.
6. After the event is monitored, wait again.


7. When the monitoring service exits or shuts down, the method of internal shutdown is called to close.

......


in order to more clearly explain the entire file folder running process. I have found a better document for you, links such as the following:

http://blog.csdn.net/cxhzqhzq/article/details/6604300

Java Advanced Applications (one)-Folder monitoring service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.