- 浏览: 38150 次
文章分类
最新评论
通过启动线程可以进行后台的操作
1.创建servlet
2.配置web.xml
3.测试
启动tomcat:
thread run: true
thread run: true
停止线程:
http://localhost:8080/itinfo/grabblogaction?method=stop
thread run: true
thread run: true
stop thread
启动线程:
http://localhost:8080/itinfo/grabblogaction?method=start
thread run: true
stop thread
start threadnull
start thread
thread run: true
thread run: true
1.创建servlet
package com.wuhao.itinfo.action; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.*; public class GrabBlogHtmlAction extends HttpServlet { /** * function:control thread state * * @author wuhao */ private static final long serialVersionUID = 1L; private GrabBlogThread gbt; private String method; @Override public void init() throws ServletException { gbt = new GrabBlogThread(); gbt.start(); } @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //get start or stop thread method = (String) request.getParameter("method"); if("stop".equals(method)){ //stop thread if(gbt != null){ gbt.stopThread(); gbt = null; System.gc(); System.out.println("stop thread"); } }else if("start".equals(method)){ System.out.println("start thread" + gbt); //start thread if(gbt == null || !gbt.isAlive()){ gbt = new GrabBlogThread(); gbt.start(); } System.out.println("start thread"); }else{ System.out.println("nothing to do"); } } /*** * * */ class GrabBlogThread extends Thread { //thread stop sign private volatile boolean stopSign = true; //stop thread public void stopThread(){ stopSign = false; } public void startThread(){ stopSign = true; } @Override public void run() { while(stopSign){ System.out.println("thread run: " + stopSign); try { sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } } } } }
2.配置web.xml
<!-- GRAB HTML --> <servlet> <servlet-name>GRABHTML</servlet-name> <servlet-class>com.wuhao.itinfo.action.GrabBlogHtmlAction</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>GRABHTML</servlet-name> <url-pattern>/grabblogaction</url-pattern> </servlet-mapping> <!-- GRAB HTML -->
3.测试
启动tomcat:
thread run: true
thread run: true
停止线程:
http://localhost:8080/itinfo/grabblogaction?method=stop
thread run: true
thread run: true
stop thread
启动线程:
http://localhost:8080/itinfo/grabblogaction?method=start
thread run: true
stop thread
start threadnull
start thread
thread run: true
thread run: true
发表评论
-
JVM内存结构及分析
2017-07-16 19:38 524JVM内存模型 名称特征 ... -
JVM调优实例
2017-06-24 12:30 01.背景:由于最近上线新增业务模块,业务量要增加所以对上线服务 ... -
音视频编码转换-ffmpeg
2016-12-30 18:42 15361.前言 由于最近在做ios与android端需要做a ... -
git did not match any file(s) known to git
2016-04-23 23:49 29491.did not match any file(s) kno ... -
Static工具类线程安全问题
2016-01-08 11:39 22941.静态方法 无论是静态方法还是实例方法,在内存中都只 ... -
JavaThread-ThreadLocal笔记
2015-12-23 14:54 5021.ThreadLocal简介 早在JDK 1.2的版本中就提 ... -
JUC-CountDownLatch笔记
2015-12-23 10:53 5311.CountDownLatch简介 CountDownLat ... -
Lambda表达式实现设计模式:命令模式
2015-10-13 09:59 668如何在使用Java 8 Lambda表达式的函数式编程方式时实 ... -
mysql 错误汇总
2015-08-12 16:49 4111.Mysql ERROR 1045 (28000): Acc ... -
Java注解
2015-08-07 11:25 01.@Retention(RetentionPolicy.RU ... -
Base64 编解码 工具类
2015-07-28 22:48 42451.工具类: import java.io.Uns ... -
HttpClient(发送字符串,multipart, 参数等)
2015-07-10 11:12 2032备注:httpclient4.5 发送MultiPart/Pa ... -
转载-搜索引擎实时秒级更新
2015-07-08 14:02 830搜索是很多用户在天 ... -
tomcat-定时任务
2015-03-30 15:27 6071.监听类 import java.util.Timer ... -
JVM-工作原理
2015-03-16 23:26 610一、 JVM的生命周期 1. J ... -
Exception in thread "main" SoapFault - faultcode: 'soapenv:Server.userException'
2015-01-20 22:32 13481.抛出此类错误大部分都是服务端发布webservice调用出 ... -
Tomcat映射虚拟目录
2015-01-19 22:43 01.设置虚拟目录 <Host>标签</H ... -
android-运行java main方法
2014-12-30 16:10 6771.右键入口类(含有Main方法的)Run Configura ... -
Mybatis 常见错误汇总
2014-12-28 22:31 01.插入数据到数据库是异常 ### Cause: java.s ... -
jsoup
2014-12-17 00:25 01. package com.wuhao.itinfo ...
相关推荐
Java 编程语言简介- 额外课程。 每周一到两个家庭作业。 教学大纲: Java 作为一种编程语言。 Java 作为独立于处理器的平台。 类和对象——继承、多态、封装、隐藏。 Java 集合框架 - 集合、列表、树、堆栈、队列、...
FSServer: 服务器启动类,依赖 Tomcat 启动时额外提供 HTTP 访问接口。 FSClient: 全功能客户端类,提供全部存、取、删操作。 FSHttpClient: HTTP 专用存文件接口,FSClient 的浅封装。 配置文件 fileserver....
当客户机第一次调用一个Stateful Session Bean 时,容器必须立即在服务器中创建一个新的Bean实例,并关联到客户机上,以后此客户机调用Stateful Session Bean 的方法时容器会把调用分派到与此客户机相关联的Bean实例...
用于请求处理的默认线程数由使用Reactor Netty的spring boot确定,该启动使用Netty的默认值。 用于将传入的json编码为服务的dto对象,并将dto的对象解码为传出的json消息。 当前的实现仅依靠普通的toJson和from...
wait是Object类的方法,对此对象调用wait方法导致本线程放弃对象锁,进入等待此对象的等待锁定池,只有针对此对象发出notify方法(或notifyAll)后本线程才进入对象锁定池准备获得对象锁进入运行状态。 14、Overload...
9.6 使用UNION运算符合并查询 9.6.1 EXCEPT运算符 9.6.2 INTERSECT运算符 9.7 小结 第10章 构建一个客户/服务器应用程序 10.1 使用不同的数据库和驱动程序 10.1.1 扩展的DBManager类 10.2 使用Database...
9.6 使用UNION运算符合并查询 9.6.1 EXCEPT运算符 9.6.2 INTERSECT运算符 9.7 小结 第10章 构建一个客户/服务器应用程序 10.1 使用不同的数据库和驱动程序 10.1.1 扩展的DBManager类 10.2 使用Database...
9.6 使用UNION运算符合并查询 9.6.1 EXCEPT运算符 9.6.2 INTERSECT运算符 9.7 小结 第10章 构建一个客户/服务器应用程序 10.1 使用不同的数据库和驱动程序 10.1.1 扩展的DBManager类 10.2 使用Database...
9.6 使用UNION运算符合并查询 9.6.1 EXCEPT运算符 9.6.2 INTERSECT运算符 9.7 小结 第10章 构建一个客户/服务器应用程序 10.1 使用不同的数据库和驱动程序 10.1.1 扩展的DBManager类 10.2 使用Database...
但它打算更容易使用,并能够在很短的时间内收集大量机器。 它完全用java编写,避免调用外部进程来提高性能。 它使用 ,它是用 java 编写的的克隆。 该网站是 这个怎么运作? JRDS 是一个 Java Web 应用程序,可以...
消息类型基于Spring Boot开发,打包后可以直接运行,不需要额外安装Tomcat等应用容器。消息本身原生客户端不依赖任何框架,能够运行于所有Java1.8 +运行时环境,同时对Spring Mvc / Spring Boot环境也有额外的支持。...
10.4.2 启动独立线程调用事务方法 10.5 联合军种作战的混乱 10.5.1 Spring事务管理器的应对 10.5.2 Hibernate+Spring JDBC混合框架的事务管理 10.6 特殊方法成漏网之鱼 10.6.1 哪些方法不能实施Spring AOP事务 ...
10.4.2 启动独立线程调用事务方法 10.5 联合军种作战的混乱 10.5.1 Spring事务管理器的应对 10.5.2 Hibernate+Spring JDBC混合框架的事务管理 10.6 特殊方法成漏网之鱼 10.6.1 哪些方法不能实施Spring AOP事务 ...