线程中断标志语义(thread interrupted flag semantics)
我在理解Java的线程中断标志的语义方面遇到了一些麻烦。 我的理解是该标志只应在线程被中断后才为真,并且一旦设置为true将不再为假,直到已捕获
InterruptedException
或等效或使用.interrupted()
显式清除该标志。 因此,我无法解释为什么以下程序打印false
:Thread t = new Thread() { @Override public void run() { try { // While await()ing, another thread calls t.interrupt(). new CyclicBarrier(2).await(); } finally { // I believe I should still be interrupted here, but am not... System.out.println(Thread.currentThread().isInterrupted()); } } };
(为简单起见,排除了一些细节 - 假设
run()
可以抛出异常。)I'm having a bit of trouble understanding the semantics for Java's thread interrupted flag. My understanding is that the flag should only be true after a thread is interrupted, and once set to true will not be false again until the
InterruptedException
or equivalent has been caught or the flag is explicitly cleared with.interrupted()
. Hence, I am not able to explain why the following program printsfalse
:Thread t = new Thread() { @Override public void run() { try { // While await()ing, another thread calls t.interrupt(). new CyclicBarrier(2).await(); } finally { // I believe I should still be interrupted here, but am not... System.out.println(Thread.currentThread().isInterrupted()); } } };
(Some details excluded for simplicity - assume it's ok for
run()
to throw exceptions.)
原文:https://stackoverflow.com/questions/21213783
最满意答案
作为一个实验,我创建了一个新的ASP.NET Webforms项目,并将其部署到IIS。 然后,我创建了第二个.NET类库,并将该.dll文件复制到Web应用程序的
\bin
文件夹中(该类库未在ASP.NET应用程序中的任何位置引用或使用)。我启动了SysInternals ProcMon,在IIS中回收了应用程序池和网站,并在浏览器中请求该网站。
w3wp.exe确实在首页请求中读取了类库.dll文件。
此MSDN页面还指出:
您可以将编译的程序集存储在Bin文件夹中,并且Web应用程序中任何位置的其他代码(例如页面代码)都会自动引用它。 一个典型的例子是你有一个自定义类的编译代码。 您可以将编译后的程序集复制到Web应用程序的Bin文件夹中,然后该类即可用于所有页面。
Bin文件夹中的程序集不需要安装在全局程序集缓存(GAC)中。 Bin文件夹中存在.dll文件足以让ASP.NET识别它。
这似乎暗示ASP.NET将反映它在
\bin
找到的程序集并自动加载它们。
有趣的是,即使你把一个非.NET文件(我将C:\ Windows中的
twain.dll
拷贝到你的ASP.NET bin文件夹中),也可以读取这些文件。 运行时似乎只是向文件系统询问\bin\*
并在文件上循环以检查要加载的.NET程序集。
我也注意到,如果你添加到你的
web.config
文件中:<system.web> <compilation targetFramework="4.5"> <assemblies> <clear /> </assemblies> </compilation>
然后页面将不再运行,并显示错误
无法加载类型'WebApplication1.Global'。
所以似乎运行时不再从程序集中加载这些类。 但是 ,运行时仍然会从驱动器中读取未引用的控制台应用程序.dll和non.net程序集twain.dll。
因此,答案归结为“加载所有dll”的含义......如果您的意思是在运行时提供,那么如果您指定了自己的
system.web | compilation | assemblies
,那么答案就是“否”system.web | compilation | assemblies
system.web | compilation | assemblies
system.web | compilation | assemblies
但默认是加载全部。 但是,如果你指的是什么文件被物理读取,那么“是”。As an experiment I made a new ASP.NET Webforms project, and deployed it to IIS. I then made a 2nd .net class library, and copied the .dll file to the web app's
\bin
folder (the class library is not referenced or used anywhere in the ASP.NET app).I started up SysInternals ProcMon, recycled the app pool and web site in IIS, and requested the site in a browser.
w3wp.exe does indeed read the class library .dll file on first page request.
This MSDN page also states:
You can store compiled assemblies in the Bin folder, and other code anywhere in the web application (such as code for pages) automatically references it. A typical example is that you have the compiled code for a custom class. You can copy the compiled assembly to the Bin folder of your Web application and the class is then available to all pages.
Assemblies in the Bin folder do not need to be installed in the Global Assembly Cache (GAC). The presence of a .dll file in the Bin folder is sufficient for ASP.NET to recognize it.
Which does seem to imply that ASP.NET will reflect over the assemblies it finds in
\bin
and automatically load them.
Interestingly, even if you put a non-.net file (I copied
twain.dll
from C:\Windows) into your ASP.NET bin folder, those files are also read. The runtime seems to just ask the filesystem for\bin\*
and loops over the files to check for .NET assemblies to load.
I also noticed that if you add this to your
web.config
file:<system.web> <compilation targetFramework="4.5"> <assemblies> <clear /> </assemblies> </compilation>
Then the page will no longer run, with the error
Could not load type 'WebApplication1.Global'.
So it seems that the runtime no longer loads those classes from the assemblies. However, the runtime still reads the non-referenced console application .dll and non-.net assembly twain.dll off the drive.
So, the answer comes down to what you mean by "loads all dlls" ... If you mean makes available in the runtime, then the answer is sort-of "no" if you specify your own
system.web | compilation | assemblies
but the default is to load all. But if you mean what files are physically read, then "yes".
相关问答
更多-
IIS已经这样做了,这就是回收的全部内容。 IT的加载DLL的应用程序的旧版本仍在运行。 只有在这完成后,回收才完成。 然而, 加载DLL只是获取Web应用程序的一部分 ,也可能会有初始加载,如加载/缓存用户数据库等。 这些操作不是回收过程的一部分 ,它们发生在所有DLL重新加载并且回收已完成之后。 前一段时间,我遇到了一个由于启动过程中数据库活动/缓存很大而导致启动时间很长的应用程序的问题。 所以我很感兴趣的是,如果有一些功能允许我们在回收标记为完成之前执行代码,那么应用程序首先会在所有内容都可以运行时被 ...
-
IIS应用程序初始化不会触发ASP.NET应用程序(IIS Application Initialization not Firing into ASP.NET Application)[2022-09-28]
经过一番深入探讨后发现,尽管我已经使用Windows 8功能安装了应用程序初始化功能,但实际的模块未添加到globalModules列表中。 以下内容缺失,一旦添加所有内容开始工作就好了: -
这看起来很像我遇到的问题,我在这篇文章中详细说明: C ++ CLI DLL不由IIS7加载,但仅在使用比VS2008更新的版本构建时才加载 基本上,Windows Web Server中缺少C ++可再发行组件包; 至少对我来说就是这样。 在要部署应用程序的远程Windows服务器上安装x86和x64 VS2010 C ++可再发行组件包,看看是否有帮助。 如果仍然无效,那么使用名为“DependencyWalker”的程序来检查您的DLL可能需要的其他内容。 DependencyWalker确实显示错误 ...
-
ASP.NET Web应用程序的哪些dll文件会加载IIS?(Which dll files of ASP.NET web application does IIS load?)[2022-06-07]
作为一个实验,我创建了一个新的ASP.NET Webforms项目,并将其部署到IIS。 然后,我创建了第二个.NET类库,并将该.dll文件复制到Web应用程序的\bin文件夹中(该类库未在ASP.NET应用程序中的任何位置引用或使用)。 我启动了SysInternals ProcMon,在IIS中回收了应用程序池和网站,并在浏览器中请求该网站。 w3wp.exe确实在首页请求中读取了类库.dll文件。 此MSDN页面还指出: 您可以将编译的程序集存储在Bin文件夹中,并且Web应用程序中任何位置的其他代 ... -
这个错误可能有多种原因。 在你的IIS服务器上安装了.Net Core Runtime ? 你的应用程序池配置是否正确? 您的网站绑定是否正确? 检查计算机上的安装运行时是否与您尝试在该项目上运行的运行时相同 That error can be for a number of reasons. On you IIS server have you installed the .Net Core Runtime? Is your application pool configured correctly? A ...
-
我的猜测是DLL是一个32位的DLL,你试图在x64环境中运行。 您可以尝试将应用程序池设置为仅32位吗? 更新:这里有一个简单的说明: http : //help.webcontrolcenter.com/KB/a1114/how-to-enable-a-32-bit-application-pool-in-iis7-dedicatedvps.aspx My guess is that the DLL is a 32-bit only DLL that you are trying to run in a ...
-
在ASP.NET Web安装项目中,我可以在IIS中禁用匿名访问吗?(In an ASP.NET Web Setup Project, can I disable anonymous access in IIS?)[2021-11-02]
取自technet 遗憾的是,匿名访问的属性不能通过Web安装项目获得。 因此,您必须: 编写自定义安装程序以启用或禁用匿名访问。 在运行时将必要的参数从安装向导传递给安装程序。 Taken from technet The property for anonymous access is unfortunately not available through Web setup projects. For this reason, you must: Write a custom installer to ... -
如何在IIS上托管基本的ASP.NET Core 2 WebAPI应用程序(How to host the basic ASP.NET Core 2 WebAPI application on IIS)[2023-06-19]
使用IIS文档在Windows上检查主机 。 现在,您似乎至少忘记安装.NET Core Windows Server Hosting软件包 。 该软件包还将安装ASP.NET核心模块,在IIS和Kestrel服务器之间创建反向代理。 Check Host on Windows with IIS documentation. Right now it looks like you at least forgot to Install the .NET Core Windows Server Hosting ... -
Asp.Net的类库项目部署除dll之外的其他文件(Class Library project for Asp.Net deploying other files than dll)[2023-07-27]
您需要将资源嵌入到类库中。 您的js,css和图像文件将包含在您的dll中,并可供您的其他项目访问。 这是一个演练。 You need to embed your resources into your class library. Your js, css and image files will then be contained within your dll and accessible to your other projects. Here is a walkthrough. -
编译ASP.NET 5 Web应用程序并生成DLL文件(Compiling an ASP.NET 5 Web Application and generating DLL files)[2022-04-15]
步骤1:确保在Build Option中检查构建时的Produce Outputs 。 (仅当选中此选项时,才会生成DLL文件。) 第2步:在发布模式下构建Web应用程序。 第3步:编译的DLLs将出现在: ..\artifacts\bin\WebAppName\Release\dnx451 。 步骤4:可以使用ILSpy检查生成的DLLs 。 步骤5:选择Web应用程序,然后单击“ 发布” 。 步骤6:转到已发布的路径: ..\approot\src\WebAppName并删除编译为DLLs所有Class ...