package com.buss.servletStart;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.buss.servletStart.Entity.IntervalTime;
public class MyServlet extends HttpServlet {
int it = 5;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
@Override
public void destroy() {
// TODO Auto-generated method stub
super.destroy();
}
@Override
public void init() throws ServletException {
// TODO Auto-generated method stub
System.out.println(“1111”);
System.out.println(it);
ThreadNutch th = new ThreadNutch(it);
new Thread(th).start();
}
}
怎么设置一个session或别的来控制线程运行的间隔时间,it是间隔时间,下面是线程的代码
package com.buss.servletStart;
import org.apache.poi.util.SystemOutLogger;
public class ThreadNutch implements Runnable {
int intervalTime = 10;
public ThreadNutch(int intervalTime){
this.intervalTime = intervalTime;
}
@Override
public void run() {
int i = 0;
while(true){
try {
Thread.sleep(intervalTime*1000);
System.out.println(“开始执行抓取x”);
System.out.println(intervalTime);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
求具体代码怎么写,间隔时间是随时可以改的 ,是在服务器运行的时候控制的
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.buss.servletStart.Entity.IntervalTime;
public class MyServlet extends HttpServlet {
int it = 5;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
@Override
public void destroy() {
// TODO Auto-generated method stub
super.destroy();
}
@Override
public void init() throws ServletException {
// TODO Auto-generated method stub
System.out.println(“1111”);
System.out.println(it);
ThreadNutch th = new ThreadNutch(it);
new Thread(th).start();
}
}
怎么设置一个session或别的来控制线程运行的间隔时间,it是间隔时间,下面是线程的代码
package com.buss.servletStart;
import org.apache.poi.util.SystemOutLogger;
public class ThreadNutch implements Runnable {
int intervalTime = 10;
public ThreadNutch(int intervalTime){
this.intervalTime = intervalTime;
}
@Override
public void run() {
int i = 0;
while(true){
try {
Thread.sleep(intervalTime*1000);
System.out.println(“开始执行抓取x”);
System.out.println(intervalTime);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
求具体代码怎么写,间隔时间是随时可以改的 ,是在服务器运行的时候控制的
解决方案
40
public class ThreadNutch implements Runnable {
public volatile static int intervalTime = 10;
…
}
修改时
ThreadNutch.intervalTime = 100;
public volatile static int intervalTime = 10;
…
}
修改时
ThreadNutch.intervalTime = 100;