java能进行java 线程池监控监控吗

-----Java 程序设计-----(10)
在程序开发中我们经常会使用到很多线程去做不同的业务,我们怎么能方便的管理这些线程呢?是否我们希望我们创建的线程能够一直运行下去,知道程序退出?在这里我们使用一个监控线程的概念。
我们可以定义一个线程继承自Thread类,在其中定义一个Map集合,用于存放我们需要管理的线程;当我们需要对某个线程进行操作时,我们就可以根据他的key值获取到;
private HashMap&String, Thread& threads2Watch = new HashMap&String, Thread&();
在run方法中,我们写一个循环,让此线程一直运行下去,并利用sleep方法,让其停顿一段时间;
while (true) {
sleep(1 * 60 * 1000);
} catch (InterruptedException e) {
DebugLog.logger.error("Exception!!", e);
注意这里的catch中加入了一个continue;即使此次sleep发生了异常,while循环仍然可以运行下去;不会对整个线程造成影响;
在while()循环中,我们就可以写自己管理线程的业务方法了,比如遍历整个map集合,获取当前线程的转态,如果线程已经结束,我们就从新开启一个这样的线程,并把它加入map集合中;
通过以上的这种做法,我们可以让我们自己程序中想要一直运行的线程一直运行下去,这种线程尤其适合在频繁监听某一网络端口,网络状态,某些值的变化是很重要的;
通过这种思想,我们可以根据自己需要扩展自己的功能;
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:3760次
排名:千里之外
原创:15篇
(1)(1)(2)(1)(10)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'相关文章推荐
Spring IOC设计原理解析:本文乃学习整理参考而来
一、 什么是Ioc/DI?
二、 Spring IOC体系结构
(1) BeanFactory
(2) BeanD...
今天是我第一次和阿里云服务器打交道,有些兴奋,有些忐忑。这是一个前端程序员对此神秘工作的开始。我用的是windows server 2012 的系统首先说一下
windows+R键
输入msts...
转载:http://littlefermat./blog/static//熟悉编写JavaScript的人,都习惯在页面写入set...
线程的状态
1. NEW(图中初始状态):一个刚创建而未启动的线程处于该状态。由于一个线程实例只能被启动一次,因此一个线程只可能有一次处于该状态。
2. 可运行(RUNNABLE):表示处于...
随着计算机技术的发展,编程模型也越来越复杂多样化。但多线程编程模型是目前计算机系统架构的最终模型。随着CPU主频的不断攀升,X86架构的硬件已经成为瓶,在这种架构的CPU主频最高为4G。事实上目前3....
相对于synchronized块中使用notify或者notifyall,通知的线程都是不确定的,当发一个通知,并不知道
下一个竞争到所得会是哪个线程。
而lock更加细腻,通过多个conditi...
在多线程开发中,经常会遇到这样的问题,比如,一个线程需要其他的一些辅助线程完成指定的一些任务后才能开
启。 类似于一个主线程正在运行,他需要其他分支线程完成一些任务后才能激活他来启动剩下的任务,这里...
vi check_tomcat_threads.c
#define OK
#define WARNING
BTW:代码都是网上找来自己修改的,仅用于自己做记录,请轻喷~谢谢
先说些废话,终于有了一份工作,是做运维,虽然和自己以前当程序员的目标有点距离,但是既然做一个工作就要把它做好,运维也不好做啊。公司分...
他的最新文章
讲师:董晓杰
讲师:姚远
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)请选择类别建议投诉 提交
关闭 原文译文操作One of the most important things for any application is performance. We want to make sure the users are getting the best experience they can, and to know that our app is up and running. That’s why most of us use at least one monitoring tool.If you’re looking for something a little different in the performance monitoring market, one option you can choose is going for an open sourced tool. In the following post we’ve gathered some open source APM tools that are available today as an alternative to the paid tools, so you’ll be able to see if it’s the right choice for you.衡量任何应用程序最重要的指标之一就是性能。 我们希望确保用户能够获得最佳的体验,并确保我们的应用程序正常运行。 这就是为什么大多数人至少使用一个监控工具的原因。如果你想在性能监控市场上寻找一些不同的东西,那么选择之一是选择一款开源工具。 在下面的博文中,我们收集了一些开源的APM工具,这些工具目前已经可以替代付费工具,你可以看看它是否是你的最佳选择。Going Open SourceThe APM market is a crowded one. You have big and well-known names such as New Relic, AppDynamics (check out
for an overview about them), along with Dynatrace (who we compared in ), along with some smaller or lesser known tools. Since there are so many players in the game, and they all know the value of , they keep their code for themselves.However, there’s an alternative in the market: open source tools. These tools present a good option if you’re interested in an easy way to gain visibility for your application in production, and if you want to know how your code is actually being monitored.拥抱开源APM市场是一个拥挤的市场。 既有许多大的和知名的名字,如New Relic,AppDynamics(查看,以了解他们的概述),以及Dynatrace(我们在中进行过比较),也有一些较小或较不知名的工具。 由于游戏中有这么多玩家竞争,他们都知道的价值,所以他们私有化他们的代码。然而,市场上有一个替代品:那就是开源工具。 如果你想要一种简单的方法来获得应用程序在生产环境中的可视化,以及如果你想知道你的代码实际上是如何被监控的,这些工具就是一个很好的选择。There are a few key APM tools in the open source community as well, each with its own offerings and possibilities. If you’re intrigued and want to know exactly what open source APM has in store for you, we’ve covered the top 5 tools available for you:StagemonitorPinpointMoSKitoGlowrootKamon1. Stagemonitor offers a Java monitoring agent, that was built with clustered application stacks in mind. Meaning that it aims to monitor applications that are running on a number of servers. The tool integrates with time series databases (TSDB). This tool is optimized for handling time series data, along with arrays of numbers that are indexed by time. These databases include Elasticsearch, Graphite, and InfluxDB.开源社区还有一些关键的APM工具,每个都有自己的产品和特性。 如果你感兴趣的话,想知道哪些开源APM等待着你,我们为你准备了前5个可用的工具:StagemonitorPinpointMoSKitoGlowrootKamon1. Stagemonitor&提供了一个Java监视代理程序,它是使用集群应用程序堆栈构建的。 意思是它的目的是监视在多个服务器上运行的应用程序。 该工具与时间序列数据库(TSDB)集成。 此工具已针对处理时间序列数据以及按时间索引的数字数组进行了优化。 这些数据库包括Elasticsearch,Graphite和InfluxDB。ArchitectureHow Does It Work?Stagemonitor includes an agent that sits in your Java application, sending metrics and request traces to the central database. The tool only requires one instance to monitor all applications, instances, and hosts and can be deployed inside your own data center.On the monitoring side, you can view historical or live data from the cluster, or directly from the developer server, create custom alerts and define thresholds for each metric.Stagemonitor includes a dashboard, so you can visualize and analyze the different metrics and requests you’re interested in. You can create custom dashboards, write your custom plugins or even use 3rd party plugins. It offers an in-browser widget with no backend required that is automatically injected to the monitored web page. You can view the live demo in the following link.架构它是如何工作的呢?Stagemonitor包含一个位于Java应用程序中的代理,可将度量标准和请求跟踪发送到中央数据库。 该工具只需要一个实例来监视所有应用程序,实例和主机,并且可以部署在您自己的数据中心内。在监控方面,你可以从集群或直接从开发人员服务器查看历史或实时数据,创建自定义警报,并为每个指标定义阈值。 Stagemonitor包含一个仪表板,因此你可以可视化并且分析您感兴趣的不同指标和请求。您可以创建自定义仪表板,编写自定义插件,甚至使用第三方插件。 它提供了一个无需后端的浏览器窗口小部件,它会自动注入受监控的网页。 您可以在以下链接中查看现场演示。In the official documentation, Stagemonitor states that it offers support for non-servlet-based applications as well, and you can .Stagemonitor’s Widget MetricsBottom line: If you’re already familiar with the ELK stack, it’s definitely worth checking out for a quick test run.2. Pinpoint is an APM tool made for large scale distributed systems. It’s modeled after Dapper, a distributed systems tracing infrastructure built by Google, providing its developers more information about the behavior of complex distributed systems.在官方文档中,Stagemonitor声明它还支持非基于servlet的应用程序,您可以&Stagemonitor&s Widget Metrics底线:如果你已经熟悉ELK堆栈,它绝对值得你尝试快速测试运行。2. PinpointPinpoint是用于大规模分布式系统的APM工具。&它是在Dapper(一个由Google构建的分布式系统跟踪基础架构)之后建模的,为其开发人员提供有关复杂分布式系统行为的更多信息。ArchitectureHow Does It Work?The tool helps analyze the overall structure of the system and how components within them are interconnected, by tracing transactions across distributed applications. Meaning that it aims to explain how every transaction gets executed, trace the flows between the components and (bad joke ahead) pinpoints problematic areas and potential bottlenecks.The dashboard helps visualize how the components are connected&and lets you monitor active threads inside the applications in real time. Pinpoint also lets you see the request count and response patterns so you’ll be able to identify potential problems. You can view critical details that include CPU usage, memory/garbage collection, and JVM arguments.体系结构它是如何工作的?这个工具可以通过跟踪分布式应用之间的交易数据,从而分析系统的整体结构以及其中的组件是如何交互的。这意味着它的目标是解释每个交易是如何执行的,跟踪组件之间的流程以及(算是个冷笑话吧?)确定有问题的地方和潜在的瓶颈。仪表板能够可视化的展示出各个组件的关联性,并使得你能够实时监控应用程序中活跃的线程。 而且Pinpoint可以让你看到请求的数量和响应的模式,这样你能够识别潜在的问题。你可以查看一些关键的详情,包括CPU使用率,内存/垃圾收集,以及JVM的参数。Pinpoint works with an agent that’s installed without any code changes, and you can run a sample instance in your own machine by running four simple scripts for each of the components: .Pinpoint’s ServerMapBottom line: If you’ve heard of Dapper, or would like to monitor and analyze your complex distributed systems, you should definitely check this tool out.3. MoSKito offers three tools in one:MoSKito-Essential: The basic standalone project. It’s the core of MoSKito functionality that lets you monitor your application.MoSKito-Central: Centralized storage server for keeping the performance data.MoSKito-Control: A tool for monitoring performance of multi-node web applications.Pinpoint使用了一个代理,安装时无需修改任何代码,而且你可以在你自己的机器上运行一个简单的实例,为这四个组件运行四个简单的脚本:.Pinpoint的&服务器映射小结:如果你听说过Dapper,或者你想要监控和分析复杂的分布式系统,&你就一定得看看这个工具。3. MoSKito 提供三种工具:MoSKito-Essential: 基本的独立项目。它是MoSKito功能的核心,可以让你监控你的应用。MoSKito-Central:&集中式的存储服务器,用于保存性能数据。MoSKito-Control:&用于监控多节点Web应用程序的性能。How Does It Work?To get started, all you need to do is drop the .jar file into the WEB-INF/lib folder or by including a small new section in the web.xml file. Once the tool is up and running, it collects performance data, analyzing it in real time as well as storing it for historical analysis.The tool collects all of your performance metrics, such as threads, memory, caches, storage, services, registrations, payments, conversion, SQL, load distribution and so on. It doesn’t require code change, supports all of the major app servers (Tomcat, Jetty, JBoss, WebLogic) and keeps the data locally.那怎么使用呢?想要开始使用的话,你需要将提供的.jar文件放在WEB-INF/lib目录下,或者在web.xml文件里加入一小段新的部分。一旦这个工具运行起来,它就会收集性能数据,实时分析并存储起来便于历史分析使用。这个工具收集所有的性能指标,比如线程数、内存、缓存、存储、服务、注册、支付、转换、SQL、载荷分布等。它不需要对代码进行修改,并支持所有的主流应用服务器(Tomcat, Jetty, JBoss, WebLogic),而且会将数据保存在本地。You also get a notification system to know when a threshold was met, and the recordings of user’s actions you want to monitor. Along with the web-based dashboards, the tool also offers a mobile app to monitor your application on the go.MoSKito’s EssentialBottom line: MoSKito first launched at 2007, and by now it’s a well known and stable tool, that’s supported by the team and by the community, including paid support options. That’s also a huge plus for any open source tool.4. Glowroot prides itself on being a fast, clean and simple APM tool. It will allow tracing capture for slow requests and errors, and you’ll be able to log time trace for each user action, as well as SQL capture and aggregation. The tool also presents a historical roll-up of all data with configurable retention.你还可以因此得到一个通知系统,能够知道何时达到设定的阈值,以及你想监控的用户行为的记录。除了基于Web的仪表板,这个工具还提供了一个移动应用,可以随时监控你的应用。MoSKito’s Essential小结:MoSKito在2007年首次推出,而且至今为止,它是一个著名而且稳定的工具,并且有团队和社区所支持,包括付费支持选项。对任何开源工具来说,这也是一个很大的加分项。4. Glowroot&是一个快速,整洁且简单的APM工具,并以此为自豪。你可以对缓慢的请求和错误进行跟踪捕获,然后你就可以对每一个用户行为、SQL捕获和聚合进行长时间的跟踪。该工具还对所有数据进行历史记录,并可以根据配置选取保留。.It provides charts to visualize response time breakdown and response time percentiles, and its responsive UI will allow you to monitor your application from your mobile devices as well as your desktop.ArchitectureGlowroot architectureHow Does It Work?To get started with Glowroot, you need to download and unzip the main installation file and add -javaagent:path/to/glowroot.jar to your application’s JVM arguments. After you start your application, all that’s left is pointing the browser to http://localhost:4000.Once the tool is up and running, you’ll get continuous profiling (with filtering options), along with being able to set up alerts for response time percentiles and MBean attributes. Glowroot offers full support for async requests that span multiple threads, and it supports Tomcat, TomEE, JBoss EAP, Wildfly, Jetty, and Glassfish.它提供了图表来可视化展示响应时间的分解和百分位占比情况,而且它的响应式UI可以使你通过桌面或者移动设备来监控你的应用。ArchitectureGlowroot 体系结构如何使用呢?要开始使用Glowroot的话,你需要下载并解压主要的安装文件,并将-javaagent:path/to/glowroot.jar 加入到你的应用的JVM参数中。在你开始了你的应用之后,剩下的就是通过浏览器来访问http://localhost:4000。一旦工具启动起来,你就会得到源源不断的分析结果(可以设置过滤选项),同时也可以设置响应时间百分比和MBean属性的警报。Glowroot 提供对跨多个线程的异步请求的完整支持,而且它还支持Tomcat, TomEE, JBoss EAP, Wildfly, Jetty, 以及Glassfish。Glowroot’s dashboardBottom line: If clean and simple is what you’re looking for, no doubt you’d want to check out Glowroot over the other tools here.5. Kamon is a reactive-friendly toolkit that is built for applications that run on top of the JVM. More specifically, it’s made for applications that are built with the Typesafe Reactive Platform (using Scala, Akka, Spray and/or Play!), but still offers support for any other JVM platforms and languages.ArchitectureHow Does It Work?Kamon is distributed as a core module with all the metric recording and trace manipulation APIs and optional modules that provide bytecode instrumentation and/or reporting capabilities to your application. Or in other words, it offers a simple API for recording metrics and trace information for JVM applications.Glowroot的仪表板小结:&如果你追求的是简单且整洁,那毫无疑问你应该首先优先考虑Glowroot这个工具,而不是其他工具。5. Kamon是为运行在JVM上的应用所构建的支持反应式交互的一个工具集。更具体的来说,它是为使用类型安全的反应式平台(Typesafe Reactive Platform,即使用Scala、Akka、Spray 或者Play!)所构建的应用所量身定做的,而且它也提供对其他任何JVM平台和语言的支持。体系结构该如何使用呢?Kamon由两部分组成,一部分是进行指标录制和提供跟踪操作APIs的核心模块,另一部分则是给应用提供字节码插装和/或报告功能的可选模块。或者换言之,它提供了一个简单的API用于对JVM应用进行各种指标以及跟踪信息的录制。All of Kamon’s modules are available through Maven Central, and you will need to add them as a compile dependency to your project. Once you’ve included the modules you’re interested in, simply start up Kamon, and all of the available modules will be automatically started, you don’t need to explicitly activate/start them.The tracing modules will allow recording data about functionality executed in your application, and the metrics module will allow you to control the registration of entities being tracked either by user code or by instrumentation provided with other Kamon modules. It also has other abilities such as filtering, configuring instrument factories and dispatching metrics subscriptions.Kamon的所有模块都可以从Maven中央库获取到,你只需要将它们作为编译的依赖加入你的项目中即可使用。一旦你将你感兴趣的模块加入进来之后,只需要简单的启动Kamon,那么所有可用的模块也就会自动启动起来了,你都不需要显示的去激活或者启动它们。跟踪模块可以使你记录你的应用中所执行的功能的数据,而指标模块则使你能够通过用户代码或者由其他Kamon模块提供的工具来控制实体的注册登记。它还拥有其它的功能,比如过滤、配置工具工厂以及调度指标的订阅。Bottom line: If you’re using a number of JVM languages, or mostly Scala / Akka, and would like “one tool to monitor them all”, Kamon might be the friendliest choice to go for.Now That You’ve Got Your Haystack…APM tools are great at giving you the information about whether your application is up and running, or if there’s something that’s holding it back. The only problem is that once you get that haystack in which the problem was found, you have to start digging around looking for the actual needle that caused it.Final ThoughtsThese are some good alternatives to the paid tools in the APM space. BUT… Some might think that going for the open source option is mostly a way to save a few bucks. It’s also important to remember that while you won’t need to issue an invoice for the use of the tool, it doesn’t necessarily mean it’s cheaper.小结:&如果你在使用很多JVM语言,或者主要是Scala / Akka,并且想要“一个工具把它们都监控起来”,那么Kamon可能是最友好的选择了。既然你已经有了干草堆…APM 工具最擅长给你提供关于你的应用是否正在运行或有什么东西在拖慢它的信息。唯一的问题在于一旦你知道了问题被发现时所在的那个干草堆,你就需要开始深入挖掘寻找真正导致问题产生的那根针。最后的思考这些都是一些不错的选择,可以用来替代那些付费的APM工具。但是…有些人可能会认为使用开源工具只是为了节约一些成本。同样重要的是,当你不需要为你所使用的工具掏钱的时候,它也并不一定就意味着是更便宜了。Open source tools come with a price: installation, troubleshooting and of course maintenance, which will all be done in-house, by your very own engineers or even you. And not to mention the time you might end up wasting seeking support for a specific issue only you’ve encountered, and the community never heard of.Our 2 cents is that open source can be great, but you should also keep the other costs in mind and only then reach a decision.Any other open source APM tools you think we should check out? Tell us about them in the comments below!使用开源工具是要付出代价的:安装,故障排除,当然还有维护,它们都需要你们自己的工程师,甚至是你自己来完成&。而且更甭提,当你遇到一个只有你自己才遇到的问题时,你去寻求支持而社区里的其他人却从没听说过,这个时候你浪费了不少时间。.我们的拙见是,开源可以很不错,但是你应该也要记住会有其他一些成本是必须要付出的,只有明白了这一点之后再去做决定。你认为还有其他哪些开源的APM工具是值得关注的?在评论区告诉我们吧。coYee —— We make translation more simple. 关注微信公众号7被浏览374分享邀请回答22 条评论分享收藏感谢收起本帖子已过去太久远了,不再提供回复功能。}

我要回帖

更多关于 java 线程监控工具 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信