Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
540b98ae
Commit
540b98ae
authored
12 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Limit the number of database threads.
parent
165b5c53
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-core/src/net/sf/briar/db/DatabaseModule.java
+19
-2
19 additions, 2 deletions
briar-core/src/net/sf/briar/db/DatabaseModule.java
with
19 additions
and
2 deletions
briar-core/src/net/sf/briar/db/DatabaseModule.java
+
19
−
2
View file @
540b98ae
package
net.sf.briar.db
;
package
net.sf.briar.db
;
import
static
java
.
util
.
concurrent
.
TimeUnit
.
MILLISECONDS
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
net.sf.briar.api.clock.Clock
;
import
net.sf.briar.api.clock.Clock
;
import
net.sf.briar.api.clock.SystemClock
;
import
net.sf.briar.api.clock.SystemClock
;
...
@@ -17,11 +21,24 @@ import com.google.inject.Singleton;
...
@@ -17,11 +21,24 @@ import com.google.inject.Singleton;
public
class
DatabaseModule
extends
AbstractModule
{
public
class
DatabaseModule
extends
AbstractModule
{
/**
* The maximum number of database threads. When a task is submitted to the
* database executor and no thread is available to run it, the task will be
* queued.
*/
private
static
final
int
MAX_DB_THREADS
=
10
;
/** How many milliseconds to keep idle threads alive. */
private
static
final
int
DB_KEEPALIVE
=
60
*
1000
;
@Override
@Override
protected
void
configure
()
{
protected
void
configure
()
{
bind
(
DatabaseCleaner
.
class
).
to
(
DatabaseCleanerImpl
.
class
);
bind
(
DatabaseCleaner
.
class
).
to
(
DatabaseCleanerImpl
.
class
);
// Use an unbounded queue to prevent deadlock between submitted tasks
BlockingQueue
<
Runnable
>
queue
=
new
LinkedBlockingQueue
<
Runnable
>();
bind
(
Executor
.
class
).
annotatedWith
(
DatabaseExecutor
.
class
).
toInstance
(
bind
(
Executor
.
class
).
annotatedWith
(
DatabaseExecutor
.
class
).
toInstance
(
Executors
.
newCachedThreadPool
());
new
ThreadPoolExecutor
(
MAX_DB_THREADS
,
MAX_DB_THREADS
,
DB_KEEPALIVE
,
MILLISECONDS
,
queue
));
}
}
@Provides
@Provides
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment