17

There is this check box on Eclipse:

Preferences -> General -> Workspace -> Refresh using native hooks or polling

The Eclipse documentation says:

If this option is turned on then the workspace resources will be synchronized with their corresponding resources in the file system automatically using native refresh providers (on Windows) or a polling mechanism.

From the documentation and the check box description suggest that there is some sort of OS hook that Eclipse uses to get notifications about file changes. And it seems that this feature is emulated on OSes other than Windows using polling.

My questions are:

  1. Is this really what Eclipse is doing? I want to know if by checking this option I will have a thread constantly checking the file system. My files change externally, but some 4 times a day, and to make this feature look fine for programmers a polling would have to check the file system once a minute or so.
  2. Does that really work only on Windows? If I am using Eclipse on Linux, does that necessarily means Eclipse will go to polling mode?
  3. Finally, and more importantly, if Eclipse does that, then how does it do it? JNI?
Akira
  • 4,001
  • 1
  • 16
  • 24

3 Answers3

14

Yes, this is really what Eclipse is doing. For Mac or Linux it currently uses polling.

There is an extension point org.eclipse.core.resources.refreshProviders that can be used to provide the refresh code for each platform and people have written test plugins for Mac and Linux but they are not in the product (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=108697 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=237344 )

Source for this is org.eclipse.core.internal.refresh.MonitorManager, PollingMonitor does the polling refresh.

org.eclipse.core.internal.resources.refresh.win32.Win32RefreshProvider does the Windows refresh using native methods via JNI (it is in a Windows only plugin).

org.eclipse.core.internal.resources.refresh.win32.Win32Monitor and Win32Natives contain the core code.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Thank you for the prompt answer. I was checking grep code to find the native implementation and could not find it. Can you point me to the actual code? – Akira Nov 13 '13 at 12:08
  • 1
    Added more classes to answer. If you have the Eclipse SDK installed (or install from the update site) you should be able to open the source in Eclipse. Check the option `Include all plug-ins from target in Java search` in `Preferences > Plug-in Development` and use `Navigate > Open Type`. – greg-449 Nov 13 '13 at 12:33
6

I have found out that the option "Refresh using native hooks or polling" was the original way of doing this:

Previous Eclipse versions relied on native refresh providers (on Windows) or a polling mechanism to keep the workspace synchronized with the underlying filesystem. This capability can be still enabled by selecting Refresh using native hooks or polling on Opens the preference page Preferences > General > Workspace.

Now a new lightweight mechanism is available. Files discovered to be out-of-sync by the workspace, for example while accessing the file content by an editor, will be automatically asynchronously refreshed. If you want to refresh files this way, go to Opens the preference page Preferences > General > Workspace and select Refresh on access.

From now on I'll go only with Refresh on access.

Henrique de Sousa
  • 5,727
  • 49
  • 55
  • 2
    However 'Refresh on access' will not update if you add new files to your project. So I have both selected and am hoping the pooling method leverages the lightweight mechanism when possible. – Daniel Sokolowski Jan 26 '15 at 19:38
  • 1
    I can confirm that with this option in place, if you leave the files you need to refreshed open, when you externally edit the files, the changes are instantaneous, rather than delayed as is the case with the polling – chrismarx Nov 05 '15 at 22:15
1

"Refresh using native hooks or polling" can solve the problem about project building is not updated when files are edited using external editors. problem details

Community
  • 1
  • 1
tom
  • 11
  • 2