Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delay modificactions to the resource tree when it is locked

I'm getting the exception:

org.eclipse.core.internal.resources.ResourceException: The resource tree is locked for modifications.

After some searching I found out, that this comes from the fact that I am trying to add markers to a file. I'm doing this, when I am notified of a file change. So when my modification code is called the workspace is still in the middle of the notifying process and does not allow modifications to the resource tree.

How can I save markers so that I can add them to the file later or what would be another way to delay this changes?

like image 609
Chris Avatar asked Sep 03 '12 07:09

Chris


1 Answers

You can't modify the resource tree from a resource delta event handler (imagine the potential for complete chaos if you could). The most common approach that I know of is to schedule a Job and make the modifications within the run() method of the Job. This means you need to remember the modifications that you want to make so that they can be done within the Job. It also means you can't make too many assumptions about the state of the resource tree because theoretically some other Job might run before yours that makes changes to the tree.

like image 55
Mike Kucera Avatar answered Oct 06 '22 19:10

Mike Kucera