首页 \ 问答 \ 使用布尔值进行同步(Using boolean to synchronize)

使用布尔值进行同步(Using boolean to synchronize)

以下代码是否对List的并发访问是线程安全的?
volatile是否符合条件在这里添加任何值?

   class concurrentList{

        private AtomicBoolean locked = new AtomicBoolean(true);
        volatile List<Integer> list=new LinkedList<Integer>();
        long start = System.currentTimeMillis();
        long end = start + 60*100;


        public void push(int e){
            while(!locked.get());
            list.add(e);
            while(!locked.compareAndSet(true,false));
        }

        public int pop(){
            int elem;
            while(locked.get());
            elem=(Integer)list.remove(0);
            while(!locked.compareAndSet(false,true));
            return elem;
        }
....
}

Is the following code thread-safe on concurrent access to List?
Does the volatile qualifies add any value here?

   class concurrentList{

        private AtomicBoolean locked = new AtomicBoolean(true);
        volatile List<Integer> list=new LinkedList<Integer>();
        long start = System.currentTimeMillis();
        long end = start + 60*100;


        public void push(int e){
            while(!locked.get());
            list.add(e);
            while(!locked.compareAndSet(true,false));
        }

        public int pop(){
            int elem;
            while(locked.get());
            elem=(Integer)list.remove(0);
            while(!locked.compareAndSet(false,true));
            return elem;
        }
....
}

原文:https://stackoverflow.com/questions/44341104
更新时间:2023-02-20 07:02

最满意答案

PowerShell cmdlet没有本机方法来执行此操作。 如果需要证书信息,您可能需要下载到.Net库。

执行此操作的一种方法是使用System.Net.ServicePointManager类。 具体来说,是FindServicePoint方法。

这必须作为Invoke-WebRequest的单独操作完成。 有关方法返回值的详细信息,请参阅MSDN文档,有关您可以执行的操作的更多详细信息,但以下内容将为您提供您特别提到的数据。 有一点需要注意:我注意到,当我在实际调用Invoke-WebRequestInvoke-RestMethod之前尝试调用FindServicePoint时,服务点上的Certificate属性为null。

$StackExAPIResponse = Invoke-WebRequest https://api.stackexchange.com/users/104624?site=serverfault -TimeoutSec 3 -ErrorAction Stop
$servicePoint = [System.Net.ServicePointManager]::FindServicePoint("https://api.stackexchange.com")
$servicePoint.Certificate.GetCertHashString()
$servicePoint.Certificate.GetExpirationDateString()

The PowerShell cmdlets don't have a native way to do this. You will probably have to drop down to the .Net libraries if you want certificate information.

One way of doing this will involve using the System.Net.ServicePointManager class. In specific, the FindServicePoint method.

This will have to be done as a separate operation from the Invoke-WebRequest. See the MSDN documenation for the method and the return value for more details about what you can do, but the following would give you the data you specifically mentioned. One thing to note: I noticed that when I tried calling FindServicePoint prior to actually calling Invoke-WebRequest or Invoke-RestMethod, the Certificate property on the service point was null.

$StackExAPIResponse = Invoke-WebRequest https://api.stackexchange.com/users/104624?site=serverfault -TimeoutSec 3 -ErrorAction Stop
$servicePoint = [System.Net.ServicePointManager]::FindServicePoint("https://api.stackexchange.com")
$servicePoint.Certificate.GetCertHashString()
$servicePoint.Certificate.GetExpirationDateString()

相关问答

更多
  • 这个工作对我有用 : http : //connect.microsoft.com/PowerShell/feedback/details/419466/new-webserviceproxy-needs-force-parameter-to-ignore-ssl-errors 基本上,在PowerShell脚本中: add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; p ...
  • 您可以通过编程方式绕过本地地址的代理,甚至在完成后返回旧的旁路列表。 我的函数代理将让你这样做。 添加域名或服务器名称或其IP地址以覆盖列表: $p = proxy $p.Override += "*.domain.com" $p | proxy Invoke-WebRequest ... #you could return old override here. 否则,我认为这应该工作: $proxy = new-object System.Net.WebProxy I ...
  • 使用-ContentType "text/plain"设置内容类型标题与示例应用程序具有相同的行为。 从Invoke-WebRequest ContentType的文档: 如果省略此参数且请求方法为POST,则Invoke-WebRequest将内容类型设置为application / x-www-form-urlencoded。 否则,在呼叫中未指定内容类型。 Set the content-type header with -ContentType "text/plain" to have the sa ...
  • 所以我开始工作:我需要使用相同的sessionid为图形URL设置一个cookie: $sessionZabbix.Cookies.SetCookies("http://zabfront-eqx.noc.lan/zabbix/chart2.php", $sessionZabbix.Cookies.GetCookieHeader($zabbixLoginUrl)) SO I got it to work : I needed to set a cookie for the graph URL using t ...
  • 你可以使用omahaproxy,你将能够获得每个平台的铬版本细节的csv,你可以像这样解析它: $WebResponse = Invoke-WebRequest "https://omahaproxy.appspot.com/all" $csv = $WebResponse.Content | convertfrom-csv ($csv | ?{($_.os -eq 'win64') -and ($_.channel -eq 'stable')}).current_version you can us ...
  • 它当然看起来像编码问题,所以这里有一些你可以尝试的东西。 确保您的文件保存为UTF-8。 使用notepad.exe打开它,然后选择另存为。 在底部有一个“编码”下拉列表。 应该说是UTF-8。 如果没有,请更改它并覆盖该文件。 在Powershell中,使用type或get-content命令打印文件。 英镑符号应显示为英镑符号,而不是问号。 使用记事本(或其他编辑器)以正确的编码保存它应该解决这个问题。 可能有用的另一件事是将SOAP消息存储在编码为UTF-8(或Unicode)的单独文件中。 然后使用 ...
  • ServiceNow有一个REST API资源管理器,其中包含各种代码示例以便开始使用。 下面是我用一个管理员帐户发布到事件表中的示例。 这里有两个重要因素,用户必须拥有角色(这里有信息https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/integrate/inbound-rest/reference/r_RESTAPIRoles.html )才能使用API并且必须能够访问您要发布到的表格。 另请注意,帖子的主体需要是RA ...
  • PowerShell cmdlet没有本机方法来执行此操作。 如果需要证书信息,您可能需要下载到.Net库。 执行此操作的一种方法是使用System.Net.ServicePointManager类。 具体来说,是FindServicePoint方法。 这必须作为Invoke-WebRequest的单独操作完成。 有关方法和返回值的详细信息,请参阅MSDN文档,有关您可以执行的操作的更多详细信息,但以下内容将为您提供您特别提到的数据。 有一点需要注意:我注意到,当我在实际调用Invoke-WebReques ...
  • 尝试这个。 只是第一个: $WebResponse.AllElements|?{$_.Class -eq 'price'}|select innerText | select -first 1 每三分之一: $WebResponse.AllElements | ?{$_.Class -eq 'price'} | select innerText | select -index ((1..$WebResponse.AllElements.Count)| % {$p=$_;if(($_ %= 3) -eq 2 ...
  • [将我的评论转化为答案] 在Windows PowerShell中, Invoke-WebRequest使用Internet Explorer引擎来解析网站,除非您告诉它不要。 IE有很多限制 - 来自其可信站点/安全区域的安全模型,IE增强安全性,组策略覆盖,可能更多,看起来你已经尝试了其他一切合理的,并且值得尝试测试直接。 这个开关: Invoke-WebRequest -UseBasicParsing .... 避免IE引擎并发出HTTP请求并在C#/ .Net中处理所有响应。 权衡是你得到纯文本结 ...

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。