From 21e648a08ed52a1718dffe53b6e21b94a2f65f74 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 14 Jul 2015 10:11:24 +0000 Subject: [PATCH] Restored ExecutorService pool git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@117211 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../persistence/AccountingPersistence.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java index b7e8f3e..32da786 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistence.java @@ -3,6 +3,9 @@ */ package org.gcube.accounting.persistence; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + import org.gcube.accounting.aggregation.scheduler.AggregationScheduler; import org.gcube.accounting.datamodel.SingleUsageRecord; import org.gcube.accounting.datamodel.UsageRecord; @@ -20,13 +23,19 @@ public abstract class AccountingPersistence { protected FallbackPersistence fallback; protected AggregationScheduler aggregationScheduler; + /** + * Pool for thread execution + */ + private ExecutorService pool; + protected AccountingPersistence(){ - + this.pool = Executors.newCachedThreadPool(); } protected AccountingPersistence(FallbackPersistence fallback, AggregationScheduler aggregationScheduler){ this.fallback = fallback; this.aggregationScheduler = aggregationScheduler; + this.pool = Executors.newCachedThreadPool(); } /** @@ -117,18 +126,14 @@ public abstract class AccountingPersistence { * @throws InvalidValueException if the Record Validation Fails */ public void account(final SingleUsageRecord usageRecord) throws InvalidValueException{ - Thread thread = new Thread(){ + Runnable runnable = new Runnable(){ @Override public void run(){ validateAccountAggregate(usageRecord, true, true); } }; - thread.start(); - try { - thread.join(); - } catch (InterruptedException e) { - logger.error("Error joining Thread"); - } + pool.execute(runnable); + } public void flush() throws Exception {