gpt4 book ai didi

java - Spring 启动: Update Operation in New Thread

转载 作者:行者123 更新时间:2023-12-02 02:52:53 25 4
gpt4 key购买 nike

我的 springboot 应用程序中有如下 customDao,

@Component
public class CustomDao {

private final JdbcTemplate jdbcTemplate

@Autowired
private PlatformTransactionManager transactionManager;

def logger = LoggerFactory.getLogger(this.class);
@Autowired
public CustomDao(JdbcTemplate template) {
this.jdbcTemplate = template
}


public insertRecord(sql,params){
//insert
}

public updateRecord(sql,params){
//update
}
}

并且我正在尝试在新线程中仅异步进行更新操作,我在线程方面没有做太多工作,有人可以帮助我吗?

最佳答案

您可以将您的 updateRecord 方法修改为:

public void updateRecord(sql, params) {
Thread t = new Thread() {
//Your code to update here
}
t.start();
}

Thread t = new Thread() {...} 将创建一个新线程来完成指定的工作,t.start() 将在以下位置运行该线程背景。

关于java - Spring 启动: Update Operation in New Thread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43536273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com