Backpatch changes from hit to try to resolve race condition issues.
diff --git a/jsf/tests/org.eclipse.jst.jsf.designtime.tests/src/org/eclipse/jst/jsf/designtime/tests/TestJSPModelProcessor.java b/jsf/tests/org.eclipse.jst.jsf.designtime.tests/src/org/eclipse/jst/jsf/designtime/tests/TestJSPModelProcessor.java
index 426d6de..b0d00a1 100644
--- a/jsf/tests/org.eclipse.jst.jsf.designtime.tests/src/org/eclipse/jst/jsf/designtime/tests/TestJSPModelProcessor.java
+++ b/jsf/tests/org.eclipse.jst.jsf.designtime.tests/src/org/eclipse/jst/jsf/designtime/tests/TestJSPModelProcessor.java
@@ -24,12 +24,15 @@
 import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
 import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
 
-public class TestJSPModelProcessor extends TestCase 
+public class TestJSPModelProcessor extends TestCase
 {
     private static final int NUM_JSPS = 25;
+    private static final int WAIT_ITERATIONS = 50;
+    private static final int WAIT_SLEEP_TIME_MS = 100;
+
     private IFile _testJSP1;
     private List<IFile> _jsps;
-    
+
     private JSFFacetedTestEnvironment _jsfFactedTestEnvironment;
 
     @Override
@@ -38,20 +41,20 @@
         JSFTestUtil.setValidationEnabled(false);
         JSFTestUtil.setInternetProxyPreferences(true, "www-proxy.us.oracle.com","80");
 
-        final WebProjectTestEnvironment  projectTestEnvironment = 
+        final WebProjectTestEnvironment  projectTestEnvironment =
             new WebProjectTestEnvironment("TestJSPModelProcessor_"+getName());
         projectTestEnvironment.createProject(false);
 
-        JDTTestEnvironment jdtTestEnvironment = 
+        final JDTTestEnvironment jdtTestEnvironment =
             new JDTTestEnvironment(projectTestEnvironment);
 
         final TestFileResource input = new TestFileResource();
-        input.load(DesignTimeTestsPlugin.getDefault().getBundle(), 
-                "/testdata/bundle1.resources.data");
+        input.load(DesignTimeTestsPlugin.getDefault().getBundle(),
+        "/testdata/bundle1.resources.data");
         jdtTestEnvironment.addResourceFile("src"
                 , new ByteArrayInputStream(input.toBytes())
                 , "bundles", "bundle1.properties");
-        
+
         _testJSP1 = (IFile) projectTestEnvironment.loadResourceInWebRoot(DesignTimeTestsPlugin.getDefault().getBundle()
                 , "/testdata/testdata1.jsp.data", "testdata1.jsp");
 
@@ -59,11 +62,11 @@
         for (int i = 0; i < NUM_JSPS; i++)
         {
             _jsps.add((IFile) projectTestEnvironment.loadResourceInWebRoot(DesignTimeTestsPlugin.getDefault().getBundle()
-                , "/testdata/testdata1.jsp.data", "testdata_"+i+".jsp"));
+                    , "/testdata/testdata1.jsp.data", "testdata_"+i+".jsp"));
         }
 
         _jsfFactedTestEnvironment = new JSFFacetedTestEnvironment(projectTestEnvironment);
-        _jsfFactedTestEnvironment.initialize(IJSFCoreConstants.FACET_VERSION_1_1);    
+        _jsfFactedTestEnvironment.initialize(IJSFCoreConstants.FACET_VERSION_1_1);
     }
 
     @Override
@@ -72,7 +75,7 @@
 
     public void testGet() throws Exception
     {
-        JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
+        final JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
         assertNotNull(processor);
         assertFalse(processor.isDisposed());
     }
@@ -80,29 +83,29 @@
     public void testGetMapForScope() throws Exception
     {
         // if we not refreshed yet, then should be no symbols
-        JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
+        final JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
         assertNotNull(processor);
 
-         Map<Object, ISymbol> scopeMap = 
+        Map<Object, ISymbol> scopeMap =
             processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_REQUEST_STRING);
         assertTrue(scopeMap.isEmpty());
 
-        scopeMap = 
+        scopeMap =
             processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_SESSION_STRING);
         assertTrue(scopeMap.isEmpty());
 
-        scopeMap = 
+        scopeMap =
             processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_APPLICATION_STRING);
         assertTrue(scopeMap.isEmpty());
 
-        scopeMap = 
+        scopeMap =
             processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_NONE_STRING);
         assertTrue(scopeMap.isEmpty());
     }
 
     public void testRefreshAndGet() throws Exception
     {
-        IModelManager modelManager = StructuredModelManager.getModelManager();
+        final IModelManager modelManager = StructuredModelManager.getModelManager();
 
         IStructuredModel model = null;
 
@@ -111,32 +114,37 @@
             model = modelManager.getModelForRead(_testJSP1);
 
             // we should be the only one with a handle
-            assertFalse(model.isShared());
+            System.out.println(model.getReferenceCountForRead());
+            assertFalse(model.isSharedForRead());
 
             // if we not refreshed yet, then should be no symbols
-            JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
+            final JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
             assertNotNull(processor);
+            System.out.println(model.getReferenceCountForRead());
             // we should be the only one with a handle
-            assertFalse(model.isShared());
-    
-            Map<Object, ISymbol> scopeMap = 
+            assertFalse(model.isSharedForRead());
+
+            Map<Object, ISymbol> scopeMap =
                 processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_REQUEST_STRING);
             assertTrue(scopeMap.isEmpty());
+            System.out.println(model.getReferenceCountForRead());
             // we should be the only one with a handle
-            assertFalse(model.isShared());
-    
+            assertFalse(model.isSharedForRead());
+
             processor.refresh(false);
+            System.out.println(model.getReferenceCountForRead());
             // we should be the only one with a handle
-            assertFalse(model.isShared());
-    
+            assertFalse(model.isSharedForRead());
+
             // after refresh we should have a symbol for the loadBundle and the dataTable
-            scopeMap = 
+            scopeMap =
                 processor.getMapForScope(ISymbolConstants.SYMBOL_SCOPE_REQUEST_STRING);
             assertFalse(scopeMap.isEmpty());
             assertEquals(2, scopeMap.size());
 
             // we should be the only one with a handle
-            assertFalse(model.isShared());
+            System.out.println(model.getReferenceCountForRead());
+            assertFalse(model.isSharedForRead());
         }
         finally
         {
@@ -154,19 +162,20 @@
         // on it without an editor close event is still disposed of due
         // to the resource change event.
         // if we not refreshed yet, then should be no symbols
-        JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
+        final JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
         assertNotNull(processor);
         assertFalse(processor.isDisposed());
 
         _testJSP1.delete(true, null);
-        // file is deleted, so the processor should dispose itself on the 
+
+        // file is deleted, so the processor should dispose itself on the
         // resource change event
-        assertTrue(processor.isDisposed());
+        waitForAndAssertProcessorDisposed(processor, true);
     }
 
     public void testProjectClosure() throws Exception
     {
-        IModelManager modelManager = StructuredModelManager.getModelManager();
+        final IModelManager modelManager = StructuredModelManager.getModelManager();
 
         IStructuredModel model = null;
 
@@ -175,26 +184,26 @@
             model = modelManager.getModelForRead(_testJSP1);
 
             // we should be the only one with a handle
-            assertFalse(model.isShared());
+            assertFalse(model.isSharedForRead());
 
             // ensure that if the enclosing project of the associated IFile
             // is closed, then the processor gets disposed
-            JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
-            assertFalse(model.isShared());
+            final JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
+            assertFalse(model.isSharedForRead());
             assertNotNull(processor);
             // we should still be the only one with a handle since JSPModelProcessor
             // doesn't hold it.
             assertFalse(processor.isDisposed());
             processor.refresh(false);
-            assertFalse(model.isShared());
+            assertFalse(model.isSharedForRead());
 
             _testJSP1.getProject().close(null);
 
-            // file is deleted, so the processor should dispose itself on the 
+            // file is deleted, so the processor should dispose itself on the
             // resource change event
-            assertTrue(processor.isDisposed());
+            waitForAndAssertProcessorDisposed(processor, true);
             // final check, with processor disposed, still not shared
-            assertFalse(model.isShared());
+            assertFalse(model.isSharedForRead());
         }
         finally
         {
@@ -207,7 +216,7 @@
 
     public void testProjectDeletion() throws Exception
     {
-        IModelManager modelManager = StructuredModelManager.getModelManager();
+        final IModelManager modelManager = StructuredModelManager.getModelManager();
 
         IStructuredModel model = null;
 
@@ -216,25 +225,25 @@
             model = modelManager.getModelForRead(_testJSP1);
 
             // we should be the only one with a handle
-            assertFalse(model.isShared());
+            assertFalse(model.isSharedForRead());
 
             // ensure that if the enclosing project of the associated IFile
             // is deleted, then the processor gets disposed
-            JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
+            final JSPModelProcessor processor = JSPModelProcessor.get(_testJSP1);
             assertNotNull(processor);
             assertFalse(processor.isDisposed());
-            assertFalse(model.isShared());
+            assertFalse(model.isSharedForRead());
             // we should still be the only one with a handle since JSPModelProcessor
             // doesn't hold it.
             processor.refresh(false);
-            assertFalse(model.isShared());
-    
+            assertFalse(model.isSharedForRead());
+
             _testJSP1.getProject().delete(true,null);
-    
-            // file is deleted, so the processor should dispose itself on the 
+
+            // file is deleted, so the processor should dispose itself on the
             // resource change event
-            assertTrue(processor.isDisposed());
-            assertFalse(model.isShared());
+            waitForAndAssertProcessorDisposed(processor, true);
+            assertFalse(model.isSharedForRead());
         }
         finally
         {
@@ -251,25 +260,27 @@
         final int order[] = new int[] {6,19,10,16,14,4,13,11,24,2,3,23,20,15,17,9,1,5,22,12,21,8,18,0,7};
         assertEquals(NUM_JSPS, order.length);
 
-        for (int i = 0; i < order.length; i++)
+        for (final int element : order)
         {
-            final IFile file = _jsps.get(order[i]);
+            final IFile file = _jsps.get(element);
 
-            JSPModelProcessor processor = JSPModelProcessor.get(file);
+            final JSPModelProcessor processor = JSPModelProcessor.get(file);
             // the processor model should start out dirty since it won't
             // get refreshed unless the resource detects a change or if
             // it is explicitly refreshed
-            assertTrue(processor.isModelDirty()); 
+            assertTrue(processor.isModelDirty());
 
             // this should trigger a change event and update the model
             file.touch(null);
-            
+
             assertFalse(processor.isModelDirty());
 
             // now delete the file and ensure the processor is disposed
             file.delete(true, null);
 
-            assertTrue(processor.isDisposed());
+            // file is deleted, so the processor should dispose itself on the
+            // resource change event
+            waitForAndAssertProcessorDisposed(processor, true);
         }
     }
 
@@ -279,45 +290,71 @@
         final int order[] = new int[] {6,19,10,16,14,4,13,11,24,2,3,23,20,15,17,9,1,5,22,12,21,8,18,0,7};
         assertEquals(NUM_JSPS, order.length);
 
-        for (int i = 0; i < order.length; i++)
+        for (final int element : order)
         {
-            final IFile file = _jsps.get(order[i]);
+            final IFile file = _jsps.get(element);
 
-            JSPModelProcessor processor = JSPModelProcessor.get(file);
+            final JSPModelProcessor processor = JSPModelProcessor.get(file);
             // the processor model should start out dirty since it won't
             // get refreshed unless the resource detects a change or if
             // it is explicitly refreshed
-            assertTrue(processor.isModelDirty()); 
             // we should be the only one with a handle
+            waitForAndAssertProcessorDirty(processor, true);
 
             // since the model is dirty this should trigger a refresh
             processor.refresh(false);
 
-            assertFalse(processor.isModelDirty());
+            waitForAndAssertProcessorDirty(processor, false);
 
             // now delete the file and ensure the processor is disposed
             file.delete(true, null);
 
-            assertTrue(processor.isDisposed());
+            waitForAndAssertProcessorDisposed(processor, true);
         }
     }
 
-    public static void main(String[] args)
+    private void waitForAndAssertProcessorDirty(final JSPModelProcessor processor,
+            final boolean expectedValue) throws Exception
+            {
+        int i = 0;
+
+        while (i++ < WAIT_ITERATIONS && (processor.isModelDirty() != expectedValue))
+        {
+            Thread.sleep(WAIT_SLEEP_TIME_MS);
+        }
+        assertEquals(expectedValue, processor.isModelDirty());
+            }
+
+    private void waitForAndAssertProcessorDisposed(final JSPModelProcessor processor, final boolean expectedValue)
+    throws Exception
     {
-       Set<Integer> set = new TreeSet<Integer>();
-       
-       Random random = new Random();
-       
-       while(set.size() < NUM_JSPS)
-       {
-           Integer value = Integer.valueOf(Math.abs(random.nextInt()) % NUM_JSPS);
-           
-           if (!set.contains(value))
-           {
-               System.out.printf("%d,", value);
-               set.add(value);
-           }
-       }
+        int i = 0;
+
+        while (i++ < WAIT_ITERATIONS && (processor.isDisposed() != expectedValue))
+        {
+            Thread.sleep(WAIT_SLEEP_TIME_MS);
+        }
+        // file is deleted, so the processor should dispose itself on the
+        // resource change event
+        assertEquals(expectedValue, processor.isDisposed());
+    }
+
+    public static void main(final String[] args)
+    {
+        final Set<Integer> set = new TreeSet<Integer>();
+
+        final Random random = new Random();
+
+        while(set.size() < NUM_JSPS)
+        {
+            final Integer value = Integer.valueOf(Math.abs(random.nextInt()) % NUM_JSPS);
+
+            if (!set.contains(value))
+            {
+                System.out.printf("%d,", value);
+                set.add(value);
+            }
+        }
     }
 }