我使用Spring Framework的@Scheduled注释创建了一个简单的计划任务.
@Scheduled(fixedRate = 2000)
public void doSomething() {}
Run Code Online (Sandbox Code Playgroud)
现在我想在不再需要时停止这项任务.
我知道在这个方法的开头可以有一个替代方法来检查一个条件标志,但是这不会停止执行这个方法.
Spring提供什么来阻止@Scheduled任务?
我已经创建了一个Spring Boot Web应用程序,并将相同的战争部署到了tomcat容器。应用程序mongoDB使用异步连接进行连接。我正在mongodb-driver-async为此使用图书馆。
在启动时,一切正常。但是,一旦负载增加,它就会在数据库连接中显示以下异常:
org.springframework.web.context.request.async.AsyncRequestTimeoutException: null
at org.springframework.web.context.request.async.TimeoutDeferredResultProcessingInterceptor.handleTimeout(TimeoutDeferredResultProcessingInterceptor.java:42)
at org.springframework.web.context.request.async.DeferredResultInterceptorChain.triggerAfterTimeout(DeferredResultInterceptorChain.java:75)
at org.springframework.web.context.request.async.WebAsyncManager$5.run(WebAsyncManager.java:392)
at org.springframework.web.context.request.async.StandardServletAsyncWebRequest.onTimeout(StandardServletAsyncWebRequest.java:143)
at org.apache.catalina.core.AsyncListenerWrapper.fireOnTimeout(AsyncListenerWrapper.java:44)
at org.apache.catalina.core.AsyncContextImpl.timeout(AsyncContextImpl.java:131)
at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:157)
Run Code Online (Sandbox Code Playgroud)
我正在使用以下版本的软件:
一旦我重新启动了tomcat服务,一切都会开始正常运行。
请帮助,这可能是此问题的根本原因。
PS:我正在使用DeferredResultCompletableFuture创建异步REST API。
我也尝试spring.mvc.async.request-timeout在应用程序中使用并asynTimeout 在tomcat中进行配置。但是仍然出现相同的错误。
下面的函数用于JavaScript(forms.js include)用于散列密码.什么是JAVA中的等价物,
function formhash(form, password) {
console.log("Hashing form");
// Create a new element input, this will be our hashed password field.
var p = document.createElement("input");
// Add the new element to our form.
form.appendChild(p);
p.name = "p";
p.type = "hidden"
p.value = hex_sha512(password.value);
// Make sure the plaintext password doesn't get sent.
password.value = "";
// Finally submit the form.
form.submit();
}
Run Code Online (Sandbox Code Playgroud) 我试图通过 java 字符串创建表,但它显示错误,因为表不存在,但当我直接在工作台上运行相同的查询时,它运行良好。下面是我的代码
String url = "jdbc:mysql://localhost:3306/" ;
String dbname = "tweetmap";
String username = "root";
String password = "root";
try
{
// SQL Driver needed for connecting to Database
Class.forName("com.mysql.jdbc.Driver");
c = DriverManager.getConnection(url+dbname,username,password);
c.setAutoCommit(true);
stmt = c.createStatement();
//Creating the Database if not Already Present
String sql = "CREATE TABLE if not exists senti "
+ "( latitude double NULL, "
+ "longitude double NULL, "
+ "Sentiment TEXT NULL) ";
stmt.executeUpdate(sql);
if(sentiment != null){
stmt1 = c.createStatement(); …Run Code Online (Sandbox Code Playgroud)