KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > DecayCodeCompletionDataStructuresThread


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ant.internal.ui.editor;
13
14 import org.eclipse.ant.internal.ui.editor.utils.ProjectHelper;
15
16
17 public class DecayCodeCompletionDataStructuresThread extends Thread JavaDoc {
18     
19     private static final int fgDelay= 6000 * 5; //5 minutes
20

21     private static DecayCodeCompletionDataStructuresThread fgInstance;
22     
23     public static DecayCodeCompletionDataStructuresThread getDefault() {
24         if (fgInstance == null) {
25             fgInstance= new DecayCodeCompletionDataStructuresThread();
26         }
27         return fgInstance;
28     }
29     
30     /**
31      * Creates a new background thread. The thread
32      * runs with minimal priority.
33      */

34     private DecayCodeCompletionDataStructuresThread() {
35         super("Decay Ant Data Structures"); //$NON-NLS-1$
36
setPriority(Thread.MIN_PRIORITY);
37         setDaemon(true);
38         fgInstance= this;
39         setContextClassLoader(null); //don't hold on to any class loaders
40
}
41     
42     /**
43      * The background activity that is triggered when the last <code>AntModel</code> is disposed.
44      * Waits for the required delay and then nulls out the memory expensive Ant code
45      * completion data structures and reset the ProjectHelper.
46      * If an <code>AntModel</code> is created during the wait, the thread is
47      * interrupted and no nulling out occurs.
48      */

49     public void run() {
50         synchronized (this) {
51             try {
52                 wait(fgDelay);
53                 AntEditorCompletionProcessor.resetCodeCompletionDataStructures();
54                 ProjectHelper.reset();
55             } catch (InterruptedException JavaDoc x) {
56             }
57         }
58     }
59     
60     /**
61      * Cancels the background thread.
62      */

63     public static void cancel() {
64         if (fgInstance != null) {
65             synchronized (fgInstance) {
66                 fgInstance.interrupt();
67                 fgInstance= null;
68             }
69         }
70     }
71 }
72
Popular Tags