Don被搁置,成为珍视物的典型变量。 创建rel=“noreferer”>SppleedExcutorservice/code>。
E.g.
@WebListener
public class Config implements ServletContextListener {
private ScheduledExecutorService scheduler;
@Override
public void contextInitialized(ServletContextEvent event) {
Data data = new Data(); // Your class which reads and holds data upon construction.
event.getServletContext().setAttribute("data", data);
scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Reloader(data), 0, 1, TimeUnit.DAYS);
}
@Override
public void contextDestroyed(ServletContextEvent event) {
scheduler.shutdownNow();
}
}
页: 1
public class Reloader implements Runnable {
private Data data;
public Reloader(Data data) {
this.data = data;
}
@Override
public void run() {
data.reload();
}
}
它可以随意取用。
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
Data data = (Data) getServletContext().getAttribute("data");
// ...
}
即便是随机联合调查组。
${data.something}