asynchronous - Java Spring Async Execution -




using jhipster on spring boot 1.5.4, i'm having hard time getting background tasks execute asynchronously; appear running synchronously using different taskexecutor , thread pool 1 i've configured.

all happens in service, bevity, defined so:

@service @transactional public class appservice {     @scheduled(fixeddelay = 3000)     public void consumedata() {         // connect subscriber , push data workerbee         for(tuple data : this.gettuples()) {             workerbee(data);         }     }      @timed     @async     public void workerbee(tuple data) throws exception {         // ... takes 300ms ....         thread.sleep(300);     } } 

arguably service isn't perfect place work, demonstration purposes, fits.

(also aside, apears @timed isn't working, read somewhere @timed doesn't work when called internally within service)

relevant section of application.yml:

jhipster:     async:         core-pool-size: 8         max-pool-size: 64         queue-capacity: 10000 

using default, generated asyncconfiguration.java, looks this:

@override @bean(name = "taskexecutor") public executor getasyncexecutor() {     log.debug("creating async task executor");     threadpooltaskexecutor executor = new threadpooltaskexecutor();     executor.setcorepoolsize(jhipsterproperties.getasync().getcorepoolsize());     executor.setmaxpoolsize(jhipsterproperties.getasync().getmaxpoolsize());     executor.setqueuecapacity(jhipsterproperties.getasync().getqueuecapacity());     executor.setthreadnameprefix("app-executor-");     return new exceptionhandlingasynctaskexecutor(executor); } 

i have verified taskexecutor bean getting created , being used liquibase.

when connect visualvm see work happening in pool-2-thread-1, must kind of default , it's obvious work happening synchronously, , not asynchronously.

things i've tried:

  • specifying executor in @async annotation @async("taskexecutor")
  • verifying configuration of taskexecutor 8 threads in core-pool-size.
  • verifying application has @enableasync annotation (it default).

looks i'm not following rules laid out here: http://www.baeldung.com/spring-async. notably self-invocation:

@async has 2 limitations:

it must applied public methods self-invocation – calling async method within same class – won’t work 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -