Spring JdbcTemplate 和线程
在 Swing 中使用 JdbcTemplate
分叉一个线程来执行插入是否安全。
这是一个日志记录事件,我尽可能不希望它影响感知的性能。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另请注意,它的线程安全性是 Spring 3.1 参考文档中有很好的解释:
13.2.1.2 JdbcTemplate 最佳实践
Also note that its thread-safety is very well explained in the Spring 3.1 reference documentation:
13.2.1.2 JdbcTemplate best practices
Spring 论坛的这个答案说是.t=25965
JdbcTemplate 是一个单例,一旦设置就不会更改状态。
This answer from the Spring forum says yes.t=25965
JdbcTemplate is a singleton that won't change state once it's set.
你为什么认为不会呢?
我没有直接从 Swing 使用
JdbcTemplate
,但我在几个 Web 应用程序中使用过(每个请求都有一个单独的线程),而且我从未遇到过任何线程问题。 在这种情况下,模板在应用程序启动时配置一次,并使用不同的参数重复调用。如果您担心线程问题,您始终可以为每个日志记录线程创建一个新模板...
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...