/**
* {@code true} if the transaction is read-only.
* Defaults to {@code false}.
* <p>This just serves as a hint for the actual transaction subsystem;
* it will <i>not necessarily</i> cause failure of write access attempts.
* A transaction manager which cannot interpret the read-only hint will
* <i>not</i> throw an exception when asked for a read-only transaction.
* @see org.springframework.transaction.interceptor.TransactionAttribute#isReadOnly()
*/
boolean readOnly() default false;
# 1 楼答案
定义非常直截了当:当且仅当您确保事务中没有发生更新、插入或删除操作时,才可以使用
readonly=true
。 如果支持,这将优化dbms的锁定行为默认情况下
readonly
为false致以最良好的祝愿
萨姆
编辑
# 2 楼答案
当您仅从数据库中读取/选择而不更改任何数据时-通过执行更新/插入/删除
如果您可以指定readOnly,那么您应该知道它的资源密集度要低得多
# 3 楼答案
自定义隔离级别可以为事务添加更多控制
如果知道某个方法将是只读的,则应该指定它
如果readonly=true,则表示您对事务管理器说,一个特定的方法将只从数据库中读取。这有两个好处:
首先,它可以比其他的更快,因为它允许DBMS优化事务(如果支持的话)。 其次,它可以避免死锁问题(例如,当特定表被写锁定时),因为您可以确保该方法不会执行INSERT或UPDATE
但是,您可以在这里找到有关它的所有详细信息: http://docs.spring.io/spring/docs/2.5.x/reference/transaction.html