Thursday, March 24, 2011

Spring JdbcTemplate and Threading

Is it safe to fork off a Thread to execute an insert using a JdbcTemplate in Swing.

It's a logging event and as much as possible I don't want it to affect perceived performance.

From stackoverflow
  • Why would you think that it wouldn't be?

    I've not used JdbcTemplate directly from Swing, but I have in several web applications (which have a separate thread per request) and I've never had any problems with threading issues from it. In this situation the template was configured once at application startup and repeatedly called with different parameters.

    If you're worried about threading issues, you can always create a new template per logging thread...

  • This answer from the Spring forum says yes:

    http://forum.springframework.org/showthread.php?t=25965

    JdbcTemplate is a singleton that won't change state once it's set.

0 comments:

Post a Comment