问题描述
限时送ChatGPT账号..我正在使用 Quartz 为 Web 应用程序安排后台任务.其中一些任务只是针对同一个网络应用发出请求.
I am using Quartz to schedule background tasks for a web application. Some of these tasks just fire off requests against the same web application.
我想避免依赖于任何类型的网络设置(例如,如果在数据中心内发出请求,使用我自己的域名的请求可能无法正确路由).是否有 Java API 来触发 ServletRequest 并让 Tomcat 在内部处理它(不涉及任何实际的 HTTP)?
I want to avoid depending on any kind of network settings (for example a request with my own domain name might not be routed properly if made from within the data center). Is there a Java API to fire off a ServletRequest and have it handled by Tomcat internally (without any actual HTTP involved)?
我仍然想将工作包装成一个 Servlet 请求,而不是直接调用后台任务的 Java 代码,这样我就可以回到常规 HTTP 请求作为配置选项.
I still want to wrap the work into a Servlet request rather than calling the Java code for the background tasks directly, so that I can go back to regular HTTP request as a configuration option.
Tomcat 特定的代码是可以接受的.
Tomcat-specific code is acceptable.
推荐答案
你想从那些计划任务中得到什么?标准的 Web 服务器行为是获取 HTTP 请求并使用特定数据进行响应.我假设您的任务不需要那个,即您只想执行代码库驻留在网络应用程序中的特定处理.
What do you want to get from that scheduled tasks? Standard web-server behavior is to get HTTP request and respond with particular data. I assume that your tasks don't need that, i.e. you want just to perform particular processing which codebase resides within the web-application.
如果上述假设是正确的,您可以将 servlet/jsp 逻辑与业务处理逻辑分离,并直接从您的计划任务中调用业务逻辑层类.
If the assumption above is correct you can just decouple servlet/jsp logic from business-processing logic and call business-logic layer classes directly from your scheduled tasks.
这篇关于在 Tomcat 中触发内部 ServletRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论