spring-async

Is It possible to support sync and async Application Events in Spring[5]

随声附和 提交于 2021-01-29 07:12:51
问题 <bean id="applicationEventMulticaster" class="com.test.listener.CustomApplicationEventMulticaster"> <property name="taskExecutor" > <bean class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <property name="maxPoolSize" value="10"/> <property name="corePoolSize" value="10"/> <property name="waitForTasksToCompleteOnShutdown" value="true"/> <property name="awaitTerminationSeconds" value="200"/> </bean> </property> </bean> public class CustomApplicationEventMulticaster

Spring @Cacheable and @Async annotation

谁说胖子不能爱 提交于 2020-08-06 09:15:10
问题 I have the need to cache some the results of some asynchronous computations. In detail, to overcome this issue, I am trying to use Spring 4.3 cache and asynchronous computation features. As an example, let's take the following code: @Service class AsyncService { @Async @Cacheable("users") CompletableFuture<User> findById(String usedId) { // Some code that retrieves the user relative to id userId return CompletableFuture.completedFuture(user); } } Is it possible? I mean, will the caching

providing timeout execution for a Spring AOP Aspect

久未见 提交于 2020-01-03 19:41:09
问题 How I can provide a timeout execution to a Spring AOP Aspect ? The logger method of MyAspect shouldn't take more time execution than 30 seconds, if not i would want to stop the method execution. How i can do this ? MyAspect Code : @Aspect @Component public class MyAspect { @Autowired private myService myService; @AfterReturning(pointcut = "execution(* xxxxx*(..))", returning = "paramOut") public void logger(final JoinPoint jp, Object paramOut){ Event event = (Event) paramOut; myService.save

JUnit-testing a Spring @Async void service method

柔情痞子 提交于 2019-12-18 11:44:55
问题 I have a Spring service: @Service @Transactional public class SomeService { @Async public void asyncMethod(Foo foo) { // processing takes significant time } } And I have an integration test for this SomeService : @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebAppConfiguration @IntegrationTest @Transactional public class SomeServiceIntTest { @Inject private SomeService someService; @Test public void testAsyncMethod() { Foo testData =

Spring @Async method call inside @Scheduled method

倾然丶 夕夏残阳落幕 提交于 2019-12-08 17:26:27
问题 I am using Spring boot with @EnableScheduling and @EnableAsync . I have a method which is annotated with @Scheduled . I have a few more methods, which are annotated with @Async . Now I am calling these @Async methods in the @Scheduled method and printing out the name of the current thread in the async methods. What I see is they all have same thread name, which in fact is the thread that is running the @Scheduled method. I don't see asynchronous method execution. What is wrong here? Here is

JUnit rollback transaction with @Async method

只愿长相守 提交于 2019-12-05 01:10:18
问题 I am writing an integration test using SpringJUnit4ClassRunner . I have a base class: @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration({ /*my XML files here*/}) @Ignore public class BaseIntegrationWebappTestRunner { @Autowired protected WebApplicationContext wac; @Autowired protected MockServletContext servletContext; @Autowired protected MockHttpSession session; @Autowired protected MockHttpServletRequest request; @Autowired protected MockHttpServletResponse