Database executor parameters were causing performance problems.

This commit is contained in:
akwizgran
2013-03-15 17:28:09 +00:00
parent 5f8dba7bf6
commit 3fcb30c207
5 changed files with 49 additions and 20 deletions

View File

@@ -1,12 +1,8 @@
package net.sf.briar.db;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.sql.Connection;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.Executors;
import net.sf.briar.api.clock.Clock;
import net.sf.briar.api.clock.SystemClock;
@@ -21,23 +17,11 @@ import com.google.inject.Singleton;
public class DatabaseModule extends AbstractModule {
/** The minimum number of database threads to keep in the pool. */
private static final int MIN_DB_THREADS = 1;
/** The maximum number of database threads. */
private static final int MAX_DB_THREADS = 10;
/** The time in milliseconds to keep unused database threads alive. */
private static final int DB_KEEPALIVE = 60 * 1000;
@Override
protected void configure() {
bind(DatabaseCleaner.class).to(DatabaseCleanerImpl.class);
// Database tasks may depend on each other, so use an unbounded queue
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
bind(Executor.class).annotatedWith(DatabaseExecutor.class).toInstance(
new ThreadPoolExecutor(MIN_DB_THREADS, MAX_DB_THREADS,
DB_KEEPALIVE, MILLISECONDS, queue));
Executors.newCachedThreadPool());
}
@Provides