Announcement Announcement Module
Collapse
No announcement yet.
RowMapper/ParameterizedRowMapper thread safety Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RowMapper/ParameterizedRowMapper thread safety

    Hi,

    Is it safe in a web based app (thread per request) to have static RowMappers mapping the resultset to a pojo?

    e.g. within a class you have code such as..

    Code:
    // Declare a rowmapper
    private static final CommentRowMapper commentRowMapper = new CommentRowMapper();
    
    // sample code where the row mapper is being used
    List<Comment> foundComments =  getSimpleJdbcTemplate().query(SELECT_COMMENTS_BY_REQUESTID_SQL,  commentRowMapper, requestId);
    
    // row mapper defined within a top-level class
    private static final class CommentRowMapper implements ParameterizedRowMapper<Comment> {
        public Comment mapRow(ResultSet rs, int rowNum) throws SQLException {
            Comment commentRow = new Comment();
            commentRow.setCommentText(rs.getString(Comment.COMMENT_TX));
            commentRow.setCreatedByUserId(rs.getString(Comment.CREATED_BY_USER_CD));
            return commentRow;
        }
    }
    Can I rely entirely on getSimpleJdbcTemplate() being thread-safe or is there an issue with this pattern of usage?

    Cheers for your help.. :-)
    Last edited by fewtrees; Mar 2nd, 2011, 05:03 AM.

  • #2
    Please use [ code][/code ] tags when posting code.

    As long as your class is thread safe there is no issue. JdbcTemplate is thread safe by design..

    Comment

    Working...
    X