首页 \ 问答 \ 什么是ReentrantLock#tryLock(long,TimeUnit)在尝试获取锁时做什么?(What is ReentrantLock#tryLock(long,TimeUnit) doing when it tries to aquire the lock?)

什么是ReentrantLock#tryLock(long,TimeUnit)在尝试获取锁时做什么?(What is ReentrantLock#tryLock(long,TimeUnit) doing when it tries to aquire the lock?)

什么是ReentrantLock#tryLock(long,TimeUnit)实现在尝试获取锁时执行的操作? 假设线程A拥有myLock的锁,并且线程B调用myLock.tryLock(10,SECONDS) ,线程B是否正在睡眠或等待?

换句话说,这两个实现的区别在于:

1。

while (true)
   try {
     if (readLock.tryLock())
       return;
     MILLISECONDS.sleep(5);
   }catch (InterruptedException e) {}

2。

 while (true)
   try {
     if (readLock.tryLock(5,MILLISECONDS))
       return;
   }catch (InterruptedException e) {}

What is the ReentrantLock#tryLock(long,TimeUnit) implementation doing when it tries to aquire a lock ? Assume Thread A acually owns the Lock of myLock, and Thread B call myLock.tryLock(10,SECONDS), is Thread B sleeping or waiting ?

In other words, was is the difference of this 2 implementations:

1.

while (true)
   try {
     if (readLock.tryLock())
       return;
     MILLISECONDS.sleep(5);
   }catch (InterruptedException e) {}

2.

 while (true)
   try {
     if (readLock.tryLock(5,MILLISECONDS))
       return;
   }catch (InterruptedException e) {}

原文:https://stackoverflow.com/questions/8398371
更新时间:2024-01-26 07:01

最满意答案

已经加啦,网络配置在:/etc/networking/interfaces文件中,也可在图形界面下配置。

相关问答

更多
  • 用桥接可以。。方便。。到linux里面的 应用程序-系统设置--网络设置 看看你的dns设好了没。。ip要和主机在同一个网段。。再看看你的MAC地址。。把它刷新一下。。然后在重新激活下网卡。。再到终端下输入service network restart 重启起网络服务。。应该是可以的。。 你装这个虚拟机的时候装了第一个服务没?就是用桥接上网的那个。。你再仔细检查下。。 就在那网络设置里点编辑,然后点硬件设备,把那个关联mac地址那个选项,点下探测。然后点确定,然后再把网卡重新激活下。。再到终端下输入serv ...
  • 虚拟机和宿主机选择用桥接的方式,首先你有几个外网的IP呢。一般家里面只有一个外网的IP。如果有交换机的话,你就可以选择桥接的方式。这样就是虚拟机和主机是同在一个局域网内的。他们的地位相等,可以直接上网。(前提条件是你要激活linux里面的网卡。如果不是很清楚就可以用图像化界面来配置redhat-config-network)如果你没有交换机的话你就要用别的链接方式。然后做网络地址转换。安装了虚拟机之后主机就多了两个虚拟的网卡,你可以给其中一个配置IP地址,然后再linux中把网关的地址指向主机的那个虚拟的网 ...
  • 系统配置要求不高,能装XP的电脑都能装Linux 而且即使开启特效,也不会有Vista那么夸张的系统要求。 Ubuntu Fedora OpenSUSE都是很好的版本。 初学者还是推荐Ubuntu。安装和使用都比较简单。
  • 中文输入法推荐fcitx小企鹅,我的百度空间有安装教程,你可以去看看。
  • 最简单就是打开终端 如果你是使用图形界面 --》右击桌面空白--》选择Ter那个打头的--》输入 yum install mysql
  • ubuntu还不错,以前用过,界面华丽丽的 先去这个论坛看看吧 http://forum.ubuntu.org.cn/
  • 如果是red hat 系列找到ifcfg-eth0 文件修改! 如果是ubuntu系列找到系统network下的interface进行修改!具体的你可以给我留言!
  • 三 E,(windows 7下)偷梁换柱法不刻盘grub引导C盘ubuntu 9.10正式版 或RC版的 安装步骤,不需要boot.ini grldr.mbr红字部份为关键: 千里不留行(原)转载请注明出处 1)将Windows 7的C盘的bootmgr(隐藏的)改名为:bootmg8 2)下载从C盘win7引导9.10 RC文件.rar (内含安装图、改名为bootmgr的grldr、写好的menu.lst和 linuxboot文件夹),除包内安装图,全部解压到C盘根目录。 (也可以网上别处下载gurb ...
  • 已经加啦,网络配置在:/etc/networking/interfaces文件中,也可在图形界面下配置。

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。