package io.vamp.persistence.sqlconnectionpool

import org.apache.commons.dbcp2._

protected case class DataSourceConfiguration(url: String, user: String, password: String)

object ConnectionPool {

  protected val dataSources = scala.collection.concurrent.TrieMap[DataSourceConfiguration, BasicDataSource]()

  def apply(url: String, user: String, password: String): BasicDataSource = this.synchronized {
    val conf = DataSourceConfiguration(url, user, password)
    dataSources.getOrElseUpdate(conf, {
      val datasource = new BasicDataSource()
      datasource.setUsername(user)
      datasource.setPassword(password)
      datasource.setUrl(url)
      datasource.setInitialSize(4)
      datasource
    })
  }

}

package io.vamp.persistence.sqlconnectionpool

import org.apache.commons.dbcp2._

protected case class DataSourceConfiguration(url: String, user: String, password: String)

object ConnectionPool {

  protected val dataSources = scala.collection.mutable.Map[DataSourceConfiguration, BasicDataSource]()

  def apply(url: String, user: String, password: String): BasicDataSource = {
    val conf = DataSourceConfiguration(url, user, password)
    dataSources.getOrElseUpdate(conf, {
      val datasource = new BasicDataSource()
      datasource.setUsername(user)
      datasource.setPassword(password)
      datasource.setUrl(url)
      datasource.setInitialSize(4)
      datasource
    })
  }

}

--- 
+++ 
@@ -6,9 +6,9 @@
 
 object ConnectionPool {
 
-  protected val dataSources = scala.collection.mutable.Map[DataSourceConfiguration, BasicDataSource]()
+  protected val dataSources = scala.collection.concurrent.TrieMap[DataSourceConfiguration, BasicDataSource]()
 
-  def apply(url: String, user: String, password: String): BasicDataSource = {
+  def apply(url: String, user: String, password: String): BasicDataSource = this.synchronized {
     val conf = DataSourceConfiguration(url, user, password)
     dataSources.getOrElseUpdate(conf, {
       val datasource = new BasicDataSource()
Fix for creating connection pool multiple times
