我的服务:
@Service
public class ForgetService{
@Async
public CompletableFuture<Object> getTokenService() {
Map<String, Object> map = new HashMap<>(8);
map.put("status", ErrorEnum.TOKEN_SUSSCESS.getStatus());
map.put("message", ErrorEnum.TOKEN_
我想创建一个使用@Async注解以异步方式写入数据库的方法。
我用注释@EnableAsync标记了这个类
@EnableAsync
public class FacialRecognitionAsyncImpl {
@Async
public void populateDataInPushQueue(int mediaId, int studentId) {
//myCode
}
}
在调用populateDataInPushQueue方法时,写操作应该在另一个线程中执行,流程应该从我调用此方法的类继续。但这并没有发生,程序执行正在等待此方法完成。
我需要发送一封异步方式的电子邮件,同时保存到数据库的数据。
我的方法是这样的。
//I have tried with service layer annotating.But not worked.
@EnableAsync
class MyService{
public String saveMethod(List listOfData){
mail.sendEmailQuote(listOfData);
mail.sendEmailWorkflowTaskAssignment(listOfData);
myDao.saveData(listOfData);
独立Spring应用程序中的@Async注释类中的@Service方法不会异步运行。我做错了什么?
当我直接从main类(@SpringBootApplication注释)运行相同的方法时,它可以工作。示例:
主类
@SpringBootApplication
@EnableAsync
public class Application implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
// here when I call do
我如何告诉Spring运行init方法呢?我需要获取代理异步类并对其进行一些初始化。
@Configuration
@EnableAsync
public class Config {
@Bean
public AsyncBean asyncProxyBean(){
return new AsyncBean();
}
public void init(){
doStuffWithProxy(asyncProxyBean());
}
@Bean
public String thisIsHack(){ //this runs the init code but
我需要做一件我不知道的事情,那就是最好的实践。
在我向一个特定的服务发送了一个请求之后,这个请求返回OK并将我的请求排入队列。我有一个回调服务,用于在结束时通知。
问题是,整个过程可能需要很长时间并在没有任何通知的情况下重复,之后我需要考虑超时。
这个应用程序是SpringBoot应用程序,我正在考虑在一个带有睡眠时间的服务方法上使用@EnableAsync和@Async注释。
@Configuration
@EnableAsync
public class AsyncConfiguration implements AsyncConfigurer {
@Override
p
我正尝试在Spring中使用异步注解,但是
java.lang.IllegalStateException: ThreadPoolTaskScheduler not initialized
尝试运行标记为Async的方法时出错。以下是异步的配置:
@EnableScheduling
@EnableAsync
@Configuration
public class SchedulingConfiguration implements AsyncConfigurer{
@Override
public Executor getAsyncExecutor() {