--- /dev/null
+/*******************************************************************************
+ * Copyright
+ * 2013 axYus - www.axyus.com
+ * 2013 P.Renier - paul.renier@axyus.com
+ *
+ * This file is part of XEMELIOS.
+ *
+ * XEMELIOS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * XEMELIOS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with XEMELIOS; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *******************************************************************************/
+package fr.gouv.finances.dgfip.xemelios.utils;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.Semaphore;
+
+/**
+ * @author paul.renier
+ *
+ */
+public class BlockingExecutorService {
+ private final Semaphore semaphore;
+ private final ExecutorService pool;
+
+ public BlockingExecutorService(final ExecutorService pool, final int size) {
+ this.pool = pool;
+ this.semaphore = new Semaphore(size);
+ }
+
+ public void submit(final Runnable task) throws InterruptedException {
+ this.semaphore.acquire();
+ try {
+ this.pool.execute(new Runnable() {
+ public void run() {
+ try {
+ task.run();
+ } finally {
+ BlockingExecutorService.this.semaphore.release();
+ }
+ }
+ });
+ } catch (final RejectedExecutionException e) {
+ this.semaphore.release();
+ }
+ }
+
+}