使用布尔值进行同步(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
最满意答案
PowerShell cmdlet没有本机方法来执行此操作。 如果需要证书信息,您可能需要下载到.Net库。
执行此操作的一种方法是使用
System.Net.ServicePointManager
类。 具体来说,是FindServicePoint
方法。这必须作为
Invoke-WebRequest
的单独操作完成。 有关方法和返回值的详细信息,请参阅MSDN文档,有关您可以执行的操作的更多详细信息,但以下内容将为您提供您特别提到的数据。 有一点需要注意:我注意到,当我在实际调用Invoke-WebRequest
或Invoke-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, theFindServicePoint
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 callingFindServicePoint
prior to actually callingInvoke-WebRequest
orInvoke-RestMethod
, theCertificate
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中处理所有响应。 权衡是你得到纯文本结 ...