线程在运行完成时结束?(Threads ends when run finish? [duplicate])
我想知道当run方法结束时,java中的线程是否自行关闭。
我的意思是,我有一个新的线程声明:
new Thread(new SubmitDataOnBackground(handler.getIDValue(), data, this.context)).start();
然后,在SubmitDataOnBackground中我有这个运行方法:
public void run() { SubmitDataHandler submit = new SubmitDataHandler(ID, data, this.context); submit.buildAndSubmitData(); }
buildandSubmitData完成后,线程是否自动关闭,或者我必须在任何地方添加任何代码?
我不确定是否我每次打电话给这个方法时都会打开一个新的线程,或者没关系。
我的应用程序是一个服务器,所以它永远不会结束,因为它一直处于活动状态。 我只想知道线程的数量不会超过,因为它只是在完成时创建新的线程而不关闭其他线程。
This question already has an answer here:
I want to know if a thread in java closes itself when run method ends.
I mean, I have a new thread declaration:
new Thread(new SubmitDataOnBackground(handler.getIDValue(), data, this.context)).start();
And then, in SubmitDataOnBackground I have this run method:
public void run() { SubmitDataHandler submit = new SubmitDataHandler(ID, data, this.context); submit.buildAndSubmitData(); }
After buildandSubmitData finishes, does the thread close itself or I have to add any code somewhere?
I am not sure if I am leaving a new thread opened each time I call this method or it is ok.
My application is a server so it will never ends because it is active the whole time. I just want to know the amount of threads is not outnumbered because it just creates new ones without closing the others when finish.
原文:https://stackoverflow.com/questions/29863991
最满意答案
我不认为这是可能的。 一个控制器可以平衡一个可用代理的构建,并且与构建的代理模式相匹配(如构建定义中定义的)。 除非你有大量的构建,否则我会坚持使用每个集合的单个控制器和更多的代理。 与代理(编译,测试和部署)相比,控制器的工作量非常小。
对于你的情况,我会尝试像这样:
调节器
- 门控代理1(在\\ sv-BuildAgent1上)
- 门控代理2(在\\ sv-BuildAgent2上)
- QA Agent ...(在\\ sv-BuildAgent3上)
- 其他代理商...(在\\无论何地)
- ...等等...
现在,每个Gated Build's Definition都会将Build Agent设置为“ Gated Agent * ”(位于3.高级 - > 代理设置 - > 名称过滤器中的进程选项卡下)。 现在将选择以“门控代理”开头的任何代理。 您可以根据需要轻松地将其扩展到尽可能多的代理商。
编辑:
您还可以将代码上的代码放到一个类似的结果。 这可能更容易配置。 您可以在构建代理的属性中定义标记,并配置定义以在名称过滤器(上面)的相同部分中使用它们。
I don't think this is possible. A controller can balance a build out onto which ever agents are available and that match the agent pattern of the the build (as defined in the build definition). Unless you have a serious load of build's, I would stick with a single controller per collection and more agents. The controller does very little work compared to and agent (which does the compilation, testing and deployment).
For your cases I would try something like:
Controller
- Gated Agent 1 (on \\sv-BuildAgent1)
- Gated Agent 2 (on \\sv-BuildAgent2)
- QA Agent... (on \\sv-BuildAgent3)
- Other agents... (on \\wherever)
- ...etc...
Now each of the Gated Build's Definition you would set the Build Agent to "Gated Agent *" (It's under the Process tab in 3. Advanced -> Agent Settings -> Name Filter.). This will now pick any agent that starts with "Gated Agent". You can easily scale this to as many agents on as many boxes as you need.
EDIT:
You can also put Tags on Build Agent to a achieve a similar result. This may be easier to configure. You Define the Tags in the Build Agent's properties and Configure Definitions to use them in the same section as the Name Filter (above).
相关问答
更多-
所有TFS Build组件(控制器和代理)共享相同的Windows服务和服务帐户。 您可以在TFS管理控制台中看到这一点。 All TFS Build components (controller and agents) share the same windows service and service account. You can see this in the TFS admin console.
-
TFS 2010可以在Server 2012上构建控制器和构建代理吗?(Can TFS 2010 build controllers & build agents run on Server 2012?)[2022-12-29]
Windows Server 2012不支持TFS 2010.您可以在此处找到操作系统兼容性的官方列表: http : //msdn.microsoft.com/en-ca/library/vstudio/dd578592(v = vs.100).aspx TFS 2010 is not supported with Windows Server 2012. You can find the official list of OS compatibility here: http://msdn.micros ... -
我们可以创建批处理文件来从TFS服务器对构建进行排队吗?(Can we create Batch File to queue the build from TFS server?)[2022-05-17]
您可以使用Rest API对构建进行排队 。 使用相应构建定义的日期设置构建号格式。 此博客 - Queue TFS / VSTS构建VIA PowerShell演示了如何使用powershell脚本使用适当的凭据连接到TFS,对构建进行排队,最后检索构建工件并存储包。 您还可以使用某些第三方扩展(如Trigger Build Task)来排队任何构建定义。 如果您需要在每晚的特定时间排队其他构建,只需设置一个预定的触发器 。 You could use Rest API to queue a build. ... -
您需要DAE扩展: http : //nuget.org/packages/DataAnnotationsExtensions/1.1.0.0 而不是“在构建服务器上安装DAE”它应该归结为NuGet。 Nuget已成为TFS建筑系统的一部分! http://blogs.msdn.com/b/jpricket/archive/2012/05/10/using-nuget-with-tfs-build-automation.aspx You need the DAE extenstion: http://nu ...
-
我不认为这是可能的。 一个控制器可以平衡一个可用代理的构建,并且与构建的代理模式相匹配(如构建定义中定义的)。 除非你有大量的构建,否则我会坚持使用每个集合的单个控制器和更多的代理。 与代理(编译,测试和部署)相比,控制器的工作量非常小。 对于你的情况,我会尝试像这样: 调节器 门控代理1(在\\ sv-BuildAgent1上) 门控代理2(在\\ sv-BuildAgent2上) QA Agent ...(在\\ sv-BuildAgent3上) 其他代理商...(在\\无论何地) ...等等... 现 ...
-
TFS 2015 - 构建配置 - 编辑构建 - 默认队列下拉(TFS 2015 - Build Configuration - Edit Build - Default Queue Drop Down)[2023-05-30]
配置代理程序时,它将询问您希望代理程序所在的池。 C:\TEMP\vsoagent>ConfigureAgent.cmd An existing configuration file was detected. This will update the local agent s ettings. Do you want to also replace the server registration (default is N)? Enter the name for this agent (defau ... -
你有什么特别的情况吗? 通常,在VSTS中,您可以选择在手动排队构建时直接运行哪个代理(托管): 更新: 如果您正在使用内部部署TFS(您的方案中的TFS 2015)或VSTS的私人代理。 然后,您可以在排队构建时设置“ 请求” 。 您还可以使用REST API对构建进行排队,并指定与特定代理相匹配的需求 : 例如: Param( [string]$collectionurl = "http://server:8080/tfs/DefaultCollection/", [string]$proj ...
-
基于Label的TFS队列构建(TFS Queue Build based on Label)[2024-03-05]
您可以在“GetVersion”字段中指定标签,并在开头添加一个L. 这可能是具体的构建过程定义,如果您请求私有构建。 在这里查看详细说明。 You can specifying the label in the "GetVersion" field with a L at the beginning. This is possible is the concrete build process definition and if you request a private build. Look here ... -
它不会按照您希望的方式工作。 一个代理可以是一个代理池和一个代理池的成员。 代理程序池存在于服务器级别,而不是Team Project Collection级别。 一个代理队列绑定到一个且只有一个代理池。 但是,代理池可以跨Team Project Collection边界由不同的代理队列引用。 因此,这样做的结果是您可以跨多个团队项目集合共享代理池。 在VSTS中,区别存在但不太相关 - 您不能拥有多个团队项目集合,因此代理池和代理队列或多或少相同,您只需管理它们。 您可以使用自定义功能(在代理上)和需求 ...
-
没有用于判断构建定义的API来获取IBuildDetail构建。 如上所述,您必须首先获取所有构建,并使用IBuildDetail.BuildControllerUri属性过滤掉不需要的构建。 There is no API to judge from build definition to get IBuildDetail builds. As you mentioned above, you have to get firstly get all builds, and filter out unwan ...