Confinement Within Threads
by Doug Lea


class ThreadPerSessionBasesService { // fragments
  // ...
  public void service() {
    Runnable r = new Runnable() {
      public void run() {
        OutputStream output = null;
        try {
          output = new FileOutputStream{"...");
          doService(output);
        }
        catch (IOException e) {
          handleIOFailure();
        }
        finally {
          try { if (output != null output.close();}
        }
       }
      };
      new Thread(r).start();
  }
    void doService(OutputStream s) throws IoException {
      s.write(...);
      //...possibly more hand-offs...
    }
}