OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Rev 94 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 80 Rev 83
Line 30... Line 30...
30
import org.openconcerto.utils.FileUtils;
30
import org.openconcerto.utils.FileUtils;
31
 
31
 
32
import java.io.File;
32
import java.io.File;
33
import java.io.IOException;
33
import java.io.IOException;
34
import java.util.concurrent.Executor;
34
import java.util.concurrent.Executor;
-
 
35
import java.util.concurrent.ExecutorService;
35
import java.util.concurrent.Executors;
36
import java.util.concurrent.Executors;
36
 
37
 
-
 
38
import net.jcip.annotations.GuardedBy;
-
 
39
 
37
/**
40
/**
38
 * Regroupe les objets nécessaires au framework.
41
 * Regroupe les objets nécessaires au framework.
39
 * 
42
 * 
40
 * @author Sylvain CUAZ
43
 * @author Sylvain CUAZ
41
 */
44
 */
Line 57... Line 60...
57
 
60
 
58
    public static final void setInstance(Configuration instance) {
61
    public static final void setInstance(Configuration instance) {
59
        Configuration.instance = instance;
62
        Configuration.instance = instance;
60
    }
63
    }
61
 
64
 
-
 
65
    @GuardedBy("this")
62
    private Executor nonInteractiveSQLExecutor;
66
    private ExecutorService nonInteractiveSQLExecutor;
63
 
67
 
64
    public abstract ShowAs getShowAs();
68
    public abstract ShowAs getShowAs();
65
 
69
 
66
    public abstract SQLBase getBase();
70
    public abstract SQLBase getBase();
67
 
71
 
Line 158... Line 162...
158
    }
162
    }
159
 
163
 
160
    /**
164
    /**
161
     * Signal that this conf will not be used anymore.
165
     * Signal that this conf will not be used anymore.
162
     */
166
     */
163
    public abstract void destroy();
167
    public void destroy() {
-
 
168
        synchronized (this) {
-
 
169
            if (this.nonInteractiveSQLExecutor != null) {
-
 
170
                this.nonInteractiveSQLExecutor.shutdown();
-
 
171
            }
-
 
172
        }
-
 
173
    }
164
 
174
 
165
    /**
175
    /**
166
     * An executor that should be used for background SQL requests. It can be used to limit the
176
     * An executor that should be used for background SQL requests. It can be used to limit the
167
     * concurrent number of database connections (as establishing a connection is expensive and the
177
     * concurrent number of database connections (as establishing a connection is expensive and the
168
     * server might have restrictions).
178
     * server might have restrictions).
169
     * 
179
     * 
170
     * @return a SQL executor.
180
     * @return a SQL executor.
171
     */
181
     */
172
    public Executor getNonInteractiveSQLExecutor() {
182
    public synchronized final Executor getNonInteractiveSQLExecutor() {
173
        if (this.nonInteractiveSQLExecutor == null) {
183
        if (this.nonInteractiveSQLExecutor == null) {
174
            this.nonInteractiveSQLExecutor = createNonInteractiveSQLExecutor();
184
            this.nonInteractiveSQLExecutor = createNonInteractiveSQLExecutor();
175
        }
185
        }
176
        return this.nonInteractiveSQLExecutor;
186
        return this.nonInteractiveSQLExecutor;
177
    }
187
    }
178
 
188
 
179
    protected Executor createNonInteractiveSQLExecutor() {
189
    protected ExecutorService createNonInteractiveSQLExecutor() {
180
        return Executors.newFixedThreadPool(2);
190
        return Executors.newFixedThreadPool(2);
181
    }
191
    }
182
}
192
}