ReentrantLock用例 [英] ReentrantLock use case

查看:157
本文介绍了ReentrantLock用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java的MultiThreading概念方面很差。

I am very poor in MultiThreading concepts of Java.

我正在通过ReentrantLock功能和用法。
我得到它更灵活然后同步并添加更多功能。

I was going through ReentrantLock features and usage. I got that it is more flexible then synchronized and adds few more features.

我可以看到它上面提到的例子,我很好。

I can see the examples mentioned on it and I got it well.

我无法弄清楚它在商业中有用的实时场景。

I am not able to figure out the real time scenario where exactly it will be helpful in business.

我可以看到最好避免死锁。

I can see that it will be best to avoid deadlocks.

有人能提供用例吗?没有ReentrantLock就很难解决这种用例。

Can some one provide the use case where without ReentrantLock it will be difficult to solve such use case.

或者可以指向某些链接会有所帮助。

or can point to some link will be helpful.

推荐答案

对于一个简单的案例,如何对需要性能的应用程序进行定时锁定/部分锁定。

For a simple case how about timed lock / or partial lock for a application which demands performance.

一个非常常见的例子是在线门户网站,可让您购买/预订门票(任何)。您获得了对您感兴趣的席位/资源的定时锁定。在时间到期后,如果事务未完成,任何其他客户端应用程序(线程)都可以锁定它。

A Very common example would be online portals which let you buy/book tickets(any). You get a timed lock on the seat/resource you are interested in. After the time expires and if transaction is not completed any other client application(thread) can acquire lock on it.

这篇关于ReentrantLock用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆