我想通过一个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处..谢过了...

解决方案 »

  1.   

    if(str.equals("start")   ) 
        { 
            
            thread.start();     
            
        }
    else 
        { 
              retrun;  
        } 
            
      

  2.   

    <%@   page   contentType="text/html;   charset=gbk"   %> 
    <%@   page   import="extend.TimingSendThread"%> 
    <%!
        private static TimingSendThread   thread   =   new   TimingSendThread();
    %>
    <%
        String   str=request.getParameter("flag");     if(str.equals("start")   ) 
        { 
            
            thread.start();     
            
        }else 
        { 
              thread.stop();     
        }%>
      

  3.   

    可以在Thread的run()里加个标志
    run(){
      if (flag){
        ...
      }
    }
    想停止的时候把flag设置为false就行了
      

  4.   

    1,2楼的好象都不行3楼能否帮忙改下..-----------------------TimingSendThread.java-------------------------public class TimingSendThread extends Thread{
    public void run(){
    try{
    TimingSendRow();

    }catch(Exception e){
    e.printStackTrace();
    }
    }
    public void TimingSendRow() throws Exception{
            ...........}}
      

  5.   

    嗯,最好的方式就是像 爱上猫的鱼 说的那样,定义一个标识,当要结束的时候设置为false,就结束了。
      

  6.   

    还有没有别的方法呢?...在不改动TimingSendThread类的情况下...