小编Sac*_*141的帖子

如何停止使用@Scheduled注释启动的计划任务?

我使用Spring Framework的@Scheduled注释创建了一个简单的计划任务.

 @Scheduled(fixedRate = 2000)
 public void doSomething() {}
Run Code Online (Sandbox Code Playgroud)

现在我想在不再需要时停止这项任务.

我知道在这个方法的开头可以有一个替代方法来检查一个条件标志,但是这不会停止执行这个方法.

Spring提供什么来阻止@Scheduled任务?

java spring scheduled-tasks

31
推荐指数
6
解决办法
3万
查看次数

Spring Boot + tomcat 8.5 + mongoDB,AsyncRequestTimeoutException

我已经创建了一个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)

我正在使用以下版本的软件:

  1. 春季启动-> 1.5.4.RELEASE
  2. Tomcat(作为独立的二进制文件安装)-> apache-tomcat-8.5.37
  3. Mongo DB版本:v3.4.10
  4. mongodb-driver-async:3.4.2

一旦我重新启动了tomcat服务,一切都会开始正常运行。

请帮助,这可能是此问题的根本原因。

PS:我正在使用DeferredResultCompletableFuture创建异步REST API。

我也尝试spring.mvc.async.request-timeout在应用程序中使用并asynTimeout 在tomcat中进行配置。但是仍然出现相同的错误。

java spring mongodb spring-boot tomcat8.5

10
推荐指数
1
解决办法
374
查看次数

在服务器上提交表单之前散列密码

下面的函数用于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)

javascript java hash android sha512

2
推荐指数
1
解决办法
532
查看次数

无法通过java执行创建表sql查询

我试图通过 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)

java mysql sql database

2
推荐指数
1
解决办法
527
查看次数