Skip to Content
Java性能权威指南(第2版)
book

Java性能权威指南(第2版)

by Scott Oaks
April 2022
Intermediate to advanced
348 pages
11h 21m
Chinese
Posts & Telecom Press
Content preview from Java性能权威指南(第2版)
数据库性能最佳实践
|
269
因此,不自动重试是一件好事(而且往往是唯一可用的解决方案),但这确实也意味着应
用程序要负责处理异常。应用程序可以重试事务(也许一次或两次),可以提示用户输入
不同的数据,也可以简单地通知用户操作失败。不存在一个放之四海而皆准的答案。
当两个数据源之间发生竞争的概率很小时,乐观锁的效果最好。例如有一个联合支票账
户,我和我的伴侣在一个城市的不同地方同时从我们的支票账户提现。我们中的一个会触
发乐观锁异常。即使发生这种情况,让我们中的一个重试也不会很费力,这样,再次发生
乐观锁异常的概率就几乎为零了(我预期是如此。不需要考虑在
AT
M
上提现的频率)。将
这种场景和样例股票应用程序进行对比,在真实世界中,股票数据的更新频率非常高,使
用乐观锁会适得其反。事实上,因为变化量大,股票应用程序往往会尽可能不使用锁,不
过实际的交易更新是需要锁的。
快速小结
•
事务会以两种方式影响应用程序的速度:事务的提交成本很高以及与事务
关联的锁会妨碍数据库进行扩展。
•
这两种影响是对立的。为了提交事务而等待太长时间会增加与事务关联的
锁的持有时间。特别是对于使用隔离级别更严格的事务,平衡点应该偏向
于更频繁地提交,而不是长时间地持有锁。
•
为了对
JDBC
中的事务进行细粒度的控制
,可以默认使用
TRANSACTION_READ_
UNCOMMITTED
级别,并根据需要显式锁定数据。
11.2.5
 结果集处理
典型的数据库应用程序会对一系列数据进行操作。例如,股票应用程序处理的是单只股票
的历史价格。该历史价格是通过一条 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Java数据科学实战

Java数据科学实战

Michael R. Brzustowicz, PhD
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
软件开发实践:项目驱动式的Java开发指南

软件开发实践:项目驱动式的Java开发指南

Raoul-Gabriel Urma, Richard Warburton

Publisher Resources

ISBN: 9787115587367