[resources] thread safety - project occassionally programmatically invisible [message #484027] |
Thu, 03 September 2009 19:19  |
Eclipse User |
|
|
|
I have a unit test where a project is created and opened during the setup:
workspace = ResourcesPlugin.getWorkspace();
workspace.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
workspace.getRoot().delete(true, null);
testProject = workspace.getRoot().getProject("test");
testProject.create(null);
testProject.open(null);
}
}, null);
Later on, there is code that tries to find that project in a ModalContext
thread:
workspace.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
System.out.println(workspace.getRoot().findMember("/test"));
}
}, null);
The result of the above call is unpredictable. Sometimes I get the project
but most every time it is null. Am I doing something unsafe here?
It's baffling me! Thanks for any help,
Will
|
|
|
|
Re: [resources] thread safety - project occassionally programmatically invisible [message #484033 is a reply to message #484032] |
Thu, 03 September 2009 20:20  |
Eclipse User |
|
|
|
But while I am here, can anyone tell me what IWorkspace means when it says:
" The workspace as a whole is thread safe and allows one writer concurrent
with multiple readers. It also supports mechanisms for saving and
snapshooting the current resource state."
Are concurrent readers ensured visibility to the current state? Is it
necessary to perform reads inside and IWorkspaceRunnable?
-Will
"Will Horn" <will.horn@gmail.com> wrote in message
news:h7pm1g$bdn$1@build.eclipse.org...
> Apologies, figured it out and it was my mistake.
>
> "Will Horn" <will.horn@gmail.com> wrote in message
> news:h7pitu$8o2$1@build.eclipse.org...
>>I have a unit test where a project is created and opened during the setup:
>>
>> workspace = ResourcesPlugin.getWorkspace();
>> workspace.run(new IWorkspaceRunnable() {
>> public void run(IProgressMonitor monitor) throws CoreException
>> {
>> workspace.getRoot().delete(true, null);
>> testProject = workspace.getRoot().getProject("test");
>> testProject.create(null);
>> testProject.open(null);
>> }
>> }, null);
>>
>> Later on, there is code that tries to find that project in a ModalContext
>> thread:
>>
>> workspace.run(new IWorkspaceRunnable() {
>> public void run(IProgressMonitor monitor) throws CoreException
>> {
>>
>> System.out.println(workspace.getRoot().findMember("/test"));
>> }
>> }, null);
>>
>> The result of the above call is unpredictable. Sometimes I get the
>> project but most every time it is null. Am I doing something unsafe
>> here?
>>
>> It's baffling me! Thanks for any help,
>>
>> Will
>
|
|
|
Powered by
FUDForum. Page generated in 0.05362 seconds