title: Single db connection that does not get initialised per task
body: <pre><code>public class Parser {
  
      ExecutorService pool = Executors.newFixedThreadPool(10);
  
      public void update() {
  
          Item item = new Item(subj.getName(), dateBuilder.toString(),
                  cobBuilder.toString(), interest, count);
  
          pool.submit(new ItemDispatcher(item));
      }
  
  
  
  } 
  
  
  
  public class ItemDispatcher implements Runnable {
  
      private Item item;
  
      public ItemDispatcher(Item someItem) {
  
          this.item = someItem;
  
      }
  
  
      @Override
      public void run() {
  
          try {
              new Database(item).writeToDb();
          } catch (SQLException e) {
              e.printStackTrace(); 
  
          }
  
      }
  
  }
  
  
  public class Database {
  
      private String name;
      private String date;
      private String cob;
      private String interest;
      private String count;
  
      private String _url;
      private String _userId;
      private String _password;
      private String _dbLib;
      private String _dbFile;
      private Connection _conn;
      private PreparedStatement _statement;
  
      public Database(Item item) {
  
          name = item.get_item();
          date = item.get_date();
          cob = item.get_cob();
          interest = item.get_interest();
          count = item.get_count();
      }
  
  
      public void writeToDb() {
  
          try {
  
              //statment.setString(); 
          }
  
          } catch (SQLException e) {
              e.printStackTrace();
          } 
  
  }
  </code></pre>
  
  <p>I have three different classes in package: <code>Parser</code>, <code>ItemDispatcher</code> and <code>Database</code>. I am using a thread pool that reuses a fixed number of threads (10). I receive updates in callback <code>update()</code> method in class <code>Parser</code>. As updates come in I create Item objects which submits as a runnable tasks for execution. From <code>ItemDispatcher</code> I pass the <code>item</code> to the <code>Database</code> class. I've realised there is an issue. I need Database class to connect to database, but as Threads are calling Database <code>constructo</code>r for every item, I don't want to create connection everytime, instead use one connection which gets initialised and never again. Not sure how to do this, can someone help please with some ideas and suggestions ? I dont want parser class to know about the Database class. Where can I add the connection and <code>preparedStatement</code> code ? </p>