OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 93 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 93 Rev 156
Line 16... Line 16...
16
import org.openconcerto.utils.cc.IClosure;
16
import org.openconcerto.utils.cc.IClosure;
17
import org.openconcerto.utils.cc.IPredicate;
17
import org.openconcerto.utils.cc.IPredicate;
18
 
18
 
19
import java.beans.PropertyChangeListener;
19
import java.beans.PropertyChangeListener;
20
import java.beans.PropertyChangeSupport;
20
import java.beans.PropertyChangeSupport;
-
 
21
import java.lang.Thread.UncaughtExceptionHandler;
21
import java.util.Collection;
22
import java.util.Collection;
22
import java.util.Deque;
23
import java.util.Deque;
23
import java.util.concurrent.Callable;
24
import java.util.concurrent.Callable;
24
import java.util.concurrent.CancellationException;
25
import java.util.concurrent.CancellationException;
25
import java.util.concurrent.ExecutionException;
26
import java.util.concurrent.ExecutionException;
Line 225... Line 226...
225
 
226
 
226
        this.tasksQueue = new SingleThreadedExecutor();
227
        this.tasksQueue = new SingleThreadedExecutor();
227
    }
228
    }
228
 
229
 
229
    public final void start() {
230
    public final void start() {
-
 
231
        this.start(null);
-
 
232
    }
-
 
233
 
-
 
234
    public final void start(final IClosure<Thread> customizeThread) {
-
 
235
        customizeThread(this.tasksQueue);
-
 
236
        if (customizeThread != null)
-
 
237
            customizeThread.executeChecked(this.tasksQueue);
230
        synchronized (this) {
238
        synchronized (this) {
231
            this.tasksQueue.start();
239
            this.tasksQueue.start();
232
            this.setState(RunningState.RUNNING);
240
            this.setState(RunningState.RUNNING);
233
            started();
241
            started();
234
        }
242
        }
Line 336... Line 344...
336
     */
344
     */
337
    protected void willPut(FutureTask<?> r) throws InterruptedException {
345
    protected void willPut(FutureTask<?> r) throws InterruptedException {
338
    }
346
    }
339
 
347
 
340
    /**
348
    /**
341
     * An exception was thrown by a task. This implementation merely
349
     * An exception was thrown by a task. This implementation uses
342
     * {@link Exception#printStackTrace()}.
350
     * {@link Thread#getUncaughtExceptionHandler()} or
-
 
351
     * {@link Thread#getDefaultUncaughtExceptionHandler()} if available, otherwise falls back to
-
 
352
     * just {@link Exception#printStackTrace()}. To set the handler, {@link #start(IClosure)} can be
-
 
353
     * used.
343
     * 
354
     * 
344
     * @param exn the exception thrown.
355
     * @param exn the exception thrown.
345
     */
356
     */
346
    protected void exceptionThrown(final ExecutionException exn) {
357
    protected void exceptionThrown(final ExecutionException exn) {
-
 
358
        final Thread thr = this.tasksQueue;
-
 
359
        UncaughtExceptionHandler h = thr.getUncaughtExceptionHandler();
-
 
360
        if (h == null)
-
 
361
            h = Thread.getDefaultUncaughtExceptionHandler();
-
 
362
        if (h != null) {
-
 
363
            h.uncaughtException(thr, exn);
-
 
364
        } else {
347
        exn.printStackTrace();
365
            exn.printStackTrace();
348
    }
366
        }
-
 
367
    }
349
 
368
 
350
    /**
369
    /**
351
     * Cancel all queued tasks and the current task.
370
     * Cancel all queued tasks and the current task.
352
     */
371
     */
353
    protected final void cancel() {
372
    protected final void cancel() {
Line 615... Line 634...
615
    }
634
    }
616
 
635
 
617
    private final class SingleThreadedExecutor extends DropperQueue<FutureTask<?>> {
636
    private final class SingleThreadedExecutor extends DropperQueue<FutureTask<?>> {
618
        private SingleThreadedExecutor() {
637
        private SingleThreadedExecutor() {
619
            super(SleepingQueue.this.name + System.currentTimeMillis());
638
            super(SleepingQueue.this.name + System.currentTimeMillis());
620
            customizeThread(this);
-
 
621
        }
639
        }
622
 
640
 
623
        @Override
641
        @Override
624
        protected void process(FutureTask<?> task) {
642
        protected void process(FutureTask<?> task) {
625
            if (!task.isDone()) {
643
            if (!task.isDone()) {