首页 文章 精选 留言 我的

精选列表

搜索[清理工具],共10000篇文章
优秀的个人博客,低调大师

任务调度工具Quartz入门笔记

一,导包 1)官网下载:http://www.quartz-scheduler.org/downloads/ 2)Maven <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.2.1</version> </dependency> 二,实例 1.先定义一个作业任务类,写我们的执行代码 package cn.zyzpp.quartz.demo; import java.text.SimpleDateFormat; import java.util.Date; import org.quartz.Job; import org.quartz.JobDataMap; import org.quartz.JobDetail; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.quartz.JobKey; import org.quartz.Trigger; /** * Created by yster@foxmail.com * 2018年4月9日 下午11:00:52 */ public class HelloJob implements Job { //第(2)种获取传入的参数的方法:setter方法 属性对应key的值 private String setKey; public void execute(JobExecutionContext context) throws JobExecutionException { //获取JobDetail对象 String now = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(new Date()); JobDetail detail = context.getJobDetail(); String group = detail.getKey().getGroup(); String value = detail.getJobDataMap().getString("key"); //获取Trigger对象 Trigger trigger = context.getTrigger(); value= trigger.getJobDataMap().getString("key"); //获取JobDataMap对象 //第(1)种获取传入的参数的方法 JobDataMap data = context.getMergedJobDataMap(); value = data.getString("key");//相同key 调用trigger的value //System.out.println(group + ":" + value + " at " + now + setKey); //获取Jobkey对象 JobKey jobKey = trigger.getJobKey(); String name = jobKey.getName(); group = jobKey.getGroup(); try { Thread.sleep(5000l); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(now + ":" + name + " " +group); } public String getSetKey() { return setKey; } public void setSetKey(String setKey) { this.setKey = setKey; } } 2. package cn.zyzpp.quartz.demo; import java.text.SimpleDateFormat; import java.util.Date; import org.quartz.CronScheduleBuilder; import org.quartz.CronTrigger; import org.quartz.JobBuilder; import org.quartz.SimpleScheduleBuilder; import org.quartz.SimpleTrigger; import org.quartz.TriggerBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.impl.StdSchedulerFactory; /** * Created by yster@foxmail.com 2018年4月9日 下午10:57:14 */ public class QuartzTest { public static void main(String[] args) { SimpleDateFormat sf =new SimpleDateFormat("yyyy-mm-dd hh:mm:ss"); try { // Quartz 作业:定义一个JobDetail:为Job类设置属性 JobDetail jobDetail = JobBuilder.newJob(HelloJob.class) // 定义Job类为HelloQuartz类,这是真正的执行逻辑所在 .withIdentity("job1", "group1") // 定义name/group .usingJobData("key", "job-value") // 自定义参数 .usingJobData("setKey", "setValue").build(); // System.out.println(jobDetail.getKey().getName()); // System.out.println(jobDetail.getKey().getGroup()); // System.out.println(jobDetail.getJobClass()); // 定义任务开始时间以及结束时间 Date startDate = new Date(); System.out.println("scheduler开始:" + sf.format(new Date())); startDate.setTime(new Date().getTime() + 2000); Date endDate = new Date(); endDate.setTime(startDate.getTime() + 4000); // Quartz触发器:定义一个Trigger Trigger trigger = TriggerBuilder.newTrigger() .withIdentity("trigger1", "group1") // 定义name/group // .startNow()//一旦加入scheduler,立即生效 .startAt(startDate) .endAt(endDate) .withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInSeconds(1) // 每隔一秒执行一次 .repeatForever()) // 一直执行,奔腾到老不停歇 .usingJobData("key", "trigger-value") .build(); //SimpleTrigger 在一个指定时间段内执行一次作业任务 或者在指定时间间隔内多次执行作业任务 SimpleTrigger simpleTrigger = (SimpleTrigger) TriggerBuilder .newTrigger() .withIdentity("trigger1", "group1") // 定义name/group .startAt(startDate) .withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInSeconds(2) .withRepeatCount(3)) //执行第1次后再执行3次(SimpleTrigger.REPEAT_INDEFINITELY) .build(); //CronTrigger 基于 cron 表达式,更常用 CronTrigger cronTrigger = (CronTrigger) TriggerBuilder .newTrigger() .withIdentity("trigger1", "group1") // 定义name/group .startAt(startDate) .withSchedule( //Cron表达式:[秒][分][时][日][月][周][年] (周日1-周六7,年可不写) *每 ?不关心 -至 #第 /递增 ,和 L最后 W最近工作日 CronScheduleBuilder.cronSchedule("0/2 * * * * ? * ") ) .build(); // 调度类链接“工作”和“触发器”到一起,并执行它 // 创建scheduler StdSchedulerFactory sfact = new StdSchedulerFactory(); Scheduler scheduler = sfact.getScheduler(); // 加入这个调度 返回第一次执行时间 scheduler.scheduleJob(jobDetail, cronTrigger); //System.out.println("调度器:" + sf.format(scheduler.scheduleJob(jobDetail, cronTrigger))); // 启动之 scheduler.start(); // 运行一段时间后暂停 可再次start 当前主线程不终止 Thread.sleep(10000l); // scheduler.standby(); // System.out.println("暂停:三秒后再次开启"); // Thread.sleep(3000l); // scheduler.start(); // Thread.sleep(5000l); scheduler.shutdown(true);//true等待执行的job完成后关闭scheduler,false直接关闭 System.out.println("scheduler终止" + sf.format(new Date())); } catch (Exception e) { e.printStackTrace(); } } } 三,干货 1)Cron表达式 2)/org/quartz/quartz.properties 3)集成Spring <!-- JobDetail --> <!-- (1)simpleJobDetail : 定义任务类和任务方法--> <bean id="simpleJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="myBean" /> <property name="targetMethod" value="printMessage" /> </bean> <!--(2)继承 QuartzJobBean 传参--> <bean id="firstComplexJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean"> <property name="jobClass" value="com.imooc.springquartz.quartz.FirstScheduledJob" /> <property name="jobDataMap"> <map> <entry key="anotherBean" value-ref="anotherBean" /> </map> </property> <property name="durability" value="true"/> </bean> <!--Trigger--> <!-- (1)距离当前时间1秒之后执行,之后每隔两秒钟执行一次 --> <bean id="mySimpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean"> <property name="jobDetail" ref="simpleJobDetail"/> <property name="startDelay" value="1000"/> <property name="repeatInterval" value="2000"/> </bean> <!-- (2)每隔5秒钟执行一次 --> <bean id="myCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail" ref="firstComplexJobDetail"/> <property name="cronExpression" value="0/5 * * ? * *"/> </bean> <!-- (3)Scheduler --> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="jobDetails"> <list> <ref bean="simpleJobDetail"/> <ref bean="firstComplexJobDetail"/> </list> </property> <property name="triggers"> <list> <ref bean="mySimpleTrigger"/> <ref bean="myCronTrigger"/> </list> </property> </bean> 1.MyBean.java import java.text.SimpleDateFormat; import java.util.Date; import org.springframework.stereotype.Component; @Component("myBean") public class MyBean { public void printMessage() { // 打印当前的执行时间,格式为2017-01-01 00:00:00 Date date = new Date(); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println("MyBean Executes!" + sf.format(date)); } } 2.AnotherBean.java import org.springframework.stereotype.Component; @Component("anotherBean") public class AnotherBean { public void printAnotherMessage() { System.out.println("AnotherMessage"); } } 3.FirstScheduledJob.java import java.text.SimpleDateFormat; import java.util.Date; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.springframework.scheduling.quartz.QuartzJobBean; public class FirstScheduledJob extends QuartzJobBean{ private AnotherBean anotherBean; public void setAnotherBean(AnotherBean anotherBean){ this.anotherBean = anotherBean; } @Override protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException { Date date = new Date(); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println("FirstScheduledJob Executes!" + sf.format(date)); this.anotherBean.printAnotherMessage(); } }

优秀的个人博客,低调大师

简介Valgrind工具包功能

我就不班门弄斧了。不过呢,有可能有些同学可能不知道Valgrind有哪些功能,那么我就从Valgrind的官方网站处,摘几段文字吧。 Memcheck Memcheck detects memory-management problems, and is aimed primarily at C and C++ programs. When a program is run under Memcheck's supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. As a result, Memcheck can detect if your program: Accesses memory it shouldn't (areas not yet allocated, areas that have been freed, areas past the end of heap blocks, inaccessible areas of the stack). Uses uninitialised values in dangerous ways. Leaks memory. Does bad frees of heap blocks (double frees, mismatched frees). Passes overlapping source and destination memory blocks to memcpy() and related functions. Memcheck reports these errors as soon as they occur, giving the source line number at which it occurred, and also a stack trace of the functions called to reach that line. Memcheck tracks addressability at the byte-level, and initialisation of values at the bit-level. As a result, it can detect the use of single uninitialised bits, and does not report spurious errors on bitfield operations. Memcheck runs programs about 10--30x slower than normal. Cachegrind Cachegrind is a cache profiler. It performs detailed simulation of the I1, D1 and L2 caches in your CPU and so can accurately pinpoint the sources of cache misses in your code. It identifies the number of cache misses, memory references and instructions executed for each line of source code, with per-function, per-module and whole-program summaries. It is useful with programs written in any language. Cachegrind runs programs about 20--100x slower than normal. Callgrind Callgrind, by Josef Weidendorfer, is an extension to Cachegrind . It provides all the information that Cachegrind does, plus extra information about callgraphs. It was folded into the main Valgrind distribution in version 3.2.0. Available separately is an amazing visualisation tool, KCachegrind , which gives a much better overview of the data that Callgrind collects; it can also be used to visualise Cachegrind's output. Massif Massif is a heap profiler. It performs detailed heap profiling by taking regular snapshots of a program's heap. It produces a graph showing heap usage over time, including information about which parts of the program are responsible for the most memory allocations. The graph is supplemented by a text or HTML file that includes more information for determining where the most memory is being allocated. Massif runs programs about 20x slower than normal. Helgrind Helgrind is a thread debugger which finds data races in multithreaded programs. It looks for memory locations which are accessed by more than one (POSIX p-)thread, but for which no consistently used (pthread_mutex_) lock can be found. Such locations are indicative of missing synchronisation between threads, and could cause hard-to-find timing-dependent problems. It is useful for any program that uses pthreads. It is a somewhat experimental tool, so your feedback is especially welcome here. DRD DRD is a tool for detecting errors in multithreaded C and C++ programs. The tool works for any program that uses the POSIX threading primitives or that uses threading concepts built on top of the POSIX threading primitives. While Helgrind can detect locking order violations, for most programs DRD needs less memory to perform its analysis. 原文:http://valgrind.org/info/tools.html

优秀的个人博客,低调大师

Filebeat轻量级日志采集工具

Beats 平台集合了多种单一用途数据采集器。这些采集器安装后可用作轻量型代理,从成百上千或成千上万台机器向 Logstash 或 Elasticsearch 发送数据。 一、架构图 此次试验基于前几篇文章,需要先基于前几篇文章搭建基础环境。 二、安装Filebeat 下载并安装Filebeat wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.0.1-x86_64.rpm yum install ./filebeat-6.0.1-x86_64.rpm 修改Filebeat配置文件 vim /etc/filebeat/filebeat.yml # 主配置文件 \- type: log # 文档类型 paths: \- /var/log/httpd/access.log* # 从哪里读入数据 # 输出在elasticsearch与logstash二选一即可 output.elasticsearch: #将数据输出到Elasticsearch。与下面的logstash二者选一 hosts: ["localhost:9200"] output.logstash: # 将数据传送到logstash,要配置logstash使用beats接收 hosts: ["172.18.68.14:5044"] 启动Filebeat systemctl start filebeat 三、配置Filebeat 配置Logstash接收来自Filebeat采集的数据 vim /etc/logstash/conf.d/test.conf input { beats { port => 5044 # 监听5044用于接收Filebeat传来数据 } } filter { grok { match => { "message" => "%{COMBINEDAPACHELOG}" # 匹配HTTP的日志 } remove_field => "message" # 不显示原信息,仅显示匹配后 } } output { elasticsearch { hosts => ["http://172.18.68.11:9200","http://172.18.68.12:9200","http://172.18.68.13:9200"] # 集群IP index => "logstash-%{+YYYY.MM.dd}" action => "index" document_type => "apache_logs" } } 启动Logstash /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf 四、模拟日志访问 通过curl命令来模拟客户访问,生成访问日志 curl 127.0.0.1 curl 172.18.68.51 curl 172.18.68.52 curl 172.18.68.53 五、验证信息 清除之前实验的旧数据(删除时要在对话框中输入删除),然后可以看到filebeat采集数据经过Logtash过滤再送给Elasticsearch的数据。 扩展 随着ELK日志系统逐渐升级,现在已经能基于Filebeat采集各节点日志,Logstash过滤、修剪数据,最后到ELasticsearch中进行索引构建、分词、构建搜索引擎。现在可以基于Elasticsearch的Head查看在浏览器中查看,但是Head仅仅能简单查看并不能有效进行数据分析、有好展示。要想进行数据分析、有好展示那就需要用到Kibana,Kibana依然放在下一篇文章中讲解,这里先放上架构图。

优秀的个人博客,低调大师

几个移动App测试工具

大致介绍如下: bugly:腾讯推出的移动应用崩溃检测服务,提升团队解决异常的效率。 bugHD:开发者可以追踪崩溃信息、崩溃版本、崩溃总数、发生设备和是否修复等信息。是Fir.im 团队做的产品; ----------------------------更多介绍如下,详细请参考个网站官网,及阅读相关帮助 -------------------------- Bugly 是腾讯内部使用的移动应用崩溃检测服务,同时支持 iOS和 Android 平台。目前 Bugly 已经对移动开发者开放。移动开发者在自己的 App 中接入 Bugly 的 SDK 后,就能在应用崩溃后获得信息上报。开发者可以通过 Bugly 的网站看到崩溃的概要和详情。崩溃概要包括,崩溃的列表、近日按小时统计趋势、昨天前天的崩溃次数和崩溃率。 每一类的崩溃详情包括,崩溃发生的机型和系统配置、崩溃时的运行状态、出错线程和其他线程的堆栈,甚至还有系统日志。崩溃详情让开发者了解崩溃发生时各方面的情况,从而方便开发者查找崩溃原因。 Bugly的优势在于,Bugly已经在腾讯内部使用了 4 年,产品经过了细致的内部打磨。 根据团队的介绍,Bugly是业内首家能检测卡顿 / ANR(应用主线程长时间失去响应时弹出的 “等待或关闭” 报错,在 iOS 平台一般称卡顿,Android 平台一般称 ANR )的服务。 依托腾讯的服务器,Bugly对用户在海外发生的应用崩溃也能实时上报。这个功能对于希望海外发行应用的团队很有吸引力,比如游戏海外发行商。 对于 Android 移动应用的异常监控,除了普通的Java类型崩溃,Bugly 还能检测原生崩溃。因此使用AndroidNDK开发C/C++的移动开发团队也能使用 Bugly。 Bugly 能够统计应用启动多少秒之后崩溃的用户数,方便开发者直观了解对用户伤害巨大的闪退的情况。Bugly 还能显示应用崩溃多少次以上的用户数,方便开发者了解对忠诚用户的伤害程度。 Bugly还有问题搜索功能,允许开发者输入关键字搜索相关的崩溃。比如开发者需要找到空指针引起的崩溃,只需在搜索框输入"NullPoint"即可。 Bugly 会定期为开发者提供崩溃信息日报,以数据可视化的形式总结一段时间内的崩溃情况。目前有很多海内外游戏发行商开始使用 Bugly 的服务,测试其代理游戏的用户体验和实际质量。据 Bugly 团队说明:手机QQ、QQ 播放器和QQ邮箱等全部腾讯开发的移动应用及其发行的游戏都在使用 Bugly 进行崩溃监控。 根据团队的说明,目前所有 Bugly 用户都能无限制免费使用这项服务,并且短期内没有收费计划。Bugly 是腾讯开发者服务体系开放的第一步,未来他们会在这个入口基础上陆续接入同样由内部服务平台开放而来的 RDM 灰度体验、持续集成和自动化测试(优测)等服务。 本文转自 念槐聚 博客园博客,原文链接:http://www.cnblogs.com/haochuang/p/4729872.html,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册