title: making sure one task completes before another starts in java
body: <p>Can anyone show me a way to force one task in java to complete before the next task is allows to start?  Specifically, I want to edit the code below so that the first marked two lines of code are completely finished before the next marked two lines are called.   </p>
  
  <pre><code>protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
      throws ServletException, IOException {
        String idString = req.getParameter("id");
        Long id = new Long(idString);
  //complete the actions specified on next two lines
        School school = new SchoolDAO().findSchool(id);
        req.setAttribute("school", school);
  //before even starting the actions specified on the next two lines
        List&lt;CourseSummary&gt; coursesummaries = new CourseSummaryDAO().findAllcsum(id);
        req.setAttribute("coursesummaries", coursesummaries);
  
        jsp.forward(req, resp);
  }  
  </code></pre>
  
  <hr>
  
  <h2>EDIT:</h2>
  
  <p>To better understand Fernando's suggestion, I am including some relevant parts of SchoolDAO as follows:  </p>
  
  <pre><code>public class SchoolDAO extends DataAccessObject{
      public School findSchool(Long id) {
          ResultSet rs = null;
          PreparedStatement statement = null;
          Connection connection = null;
          try {
              connection = getConnection();
              String sql = "select * from schoolprog where id=?";
              statement = connection.prepareStatement(sql);
              statement.setLong(1, id.longValue());
              rs = statement.executeQuery();
              if (!rs.next()) {return null;}
              return readSchool(rs);
           }
           catch (SQLException e) {throw new RuntimeException(e);}
           finally {close(rs, statement, connection);}
        }
        private School readSchool(ResultSet rs) throws SQLException {
            Long id = new Long(rs.getLong("id"));
            String spname = rs.getString("spname");
            String spurl = rs.getString("spurl");
            School school = new School();
            school.setId(id);
            school.setName(spname);
            school.setUrl(spurl);
            return school;
        }
  }  
  </code></pre>
  
  <p>Similarly, CourseSummaryDAO contains:  </p>
  
  <pre><code>public class CourseSummaryDAO extends DataAccessObject{
      public List&lt;CourseSummary&gt; findAllcsum(Long sid) {
          LinkedList&lt;CourseSummary&gt; coursesummaries = new LinkedList&lt;CourseSummary&gt;();
          ResultSet rs = null;
          PreparedStatement statement = null;
          Connection connection = null;
          try {
              connection = getConnection(); //this is the line throwing null pointer error
        String sql = "select * from coursetotals where spid=?";
              statement = connection.prepareStatement(sql);
              statement.setLong(1, sid);
              rs = statement.executeQuery();
        //for every row, call read method to extract column 
              //values and place them in a coursesummary instance
              while (rs.next()) {
                  CourseSummary coursesummary = readcsum("findAll", rs);
                  coursesummaries.add(coursesummary);
              }
              return coursesummaries;
           }
           catch (SQLException e) {throw new RuntimeException(e);} 
           finally {close(rs, statement, connection);}
       }
  </code></pre>
  
  <p>The line where the program is breaking is:              </p>
  
  <pre><code>connection = getConnection(); //
  </code></pre>