I am using a JDBC driver for Microsoft SQL Server 2012 (sqljdbc_4.0) and although the Connection instances are thread-safe, the Statement instances do not appear to be (particularly PreparedStatement).
I am using Scala .par.foreach method calls on some collections that then execute PreparedStatement instances. I am currently creating new PreparedStatement instances inside the closure of the .foreach to process each item, since they are not thread-safe.
Each of the PreparedStatement queries is the same, with different values substituted for the question-mark parameters (?). I am wondering if there is any way to create a pool of PreparedStatement instances equal in size to the number of threads used by the parallel collection, and then just reuse a free one for each iteration of the .foreach closure, returning them to the pool after reuse.