我想通过一个JSP页面来控制一个线程的启动和停止,该如何实现.比如:
-----------------thread.jsp---------------------
<%@ page contentType="text/html; charset=gbk" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="test.jsp" name="form1" method="post">
<select name="flag">
<option value="start">开始</option>
<option value="stop">停止</option>
</select>
<input type="submit" />
</form>
</body>
</html>
-----------------test.jsp------------------<%@ page contentType="text/html; charset=gbk" %>
<%@ page import="extend.TimingSendThread"%>
<%
String str=request.getParameter("flag");
TimingSendThread thread = new TimingSendThread();//线程,该处应如何弄????????
if(str.equals("start") )
{
thread.start();
}else
{
thread.stop();
}
%>线程启动之后停不下来,请大家帮忙改下test.jsp处..谢过了...
-----------------thread.jsp---------------------
<%@ page contentType="text/html; charset=gbk" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="test.jsp" name="form1" method="post">
<select name="flag">
<option value="start">开始</option>
<option value="stop">停止</option>
</select>
<input type="submit" />
</form>
</body>
</html>
-----------------test.jsp------------------<%@ page contentType="text/html; charset=gbk" %>
<%@ page import="extend.TimingSendThread"%>
<%
String str=request.getParameter("flag");
TimingSendThread thread = new TimingSendThread();//线程,该处应如何弄????????
if(str.equals("start") )
{
thread.start();
}else
{
thread.stop();
}
%>线程启动之后停不下来,请大家帮忙改下test.jsp处..谢过了...
{
thread.start();
}
else
{
retrun;
}
<%@ page import="extend.TimingSendThread"%>
<%!
private static TimingSendThread thread = new TimingSendThread();
%>
<%
String str=request.getParameter("flag"); if(str.equals("start") )
{
thread.start();
}else
{
thread.stop();
}%>
run(){
if (flag){
...
}
}
想停止的时候把flag设置为false就行了
public void run(){
try{
TimingSendRow();
}catch(Exception e){
e.printStackTrace();
}
}
public void TimingSendRow() throws Exception{
...........}}