Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [resources] thread safety - project occassionally programmatically invisible
[resources] thread safety - project occassionally programmatically invisible [message #484027] Thu, 03 September 2009 19:19 Go to next message
Will Horn is currently offline Will Horn
Messages: 265
Registered: July 2009
Senior Member
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 #484032 is a reply to message #484027] Thu, 03 September 2009 20:12 Go to previous messageGo to next message
Will Horn is currently offline Will Horn
Messages: 265
Registered: July 2009
Senior Member
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
Re: [resources] thread safety - project occassionally programmatically invisible [message #484033 is a reply to message #484032] Thu, 03 September 2009 20:20 Go to previous message
Will Horn is currently offline Will Horn
Messages: 265
Registered: July 2009
Senior Member
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
>
Previous Topic:Re: How to open URL contents in editor.
Next Topic:Dont show a view under Windows->Show View
Goto Forum:
  


Current Time: Mon Sep 01 07:24:50 EDT 2014

Powered by FUDForum. Page generated in 0.02446 seconds