Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Eclipse, what does "Preferences -> General -> Workspace -> Refresh using native hooks or polling" do?

Tags:

java

eclipse

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?
like image 483
Akira Avatar asked Nov 13 '13 10:11

Akira


3 Answers

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.

like image 126
greg-449 Avatar answered Nov 07 '22 01:11

greg-449


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.

like image 35
Henrique de Sousa Avatar answered Nov 07 '22 03:11

Henrique de Sousa


"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

like image 1
tom Avatar answered Nov 07 '22 01:11

tom