java - How to configure Async and Sync Event publishers using spring -



java - How to configure Async and Sync Event publishers using spring -

i trying implement event framework using spring events.i came know default behavior of spring event framework sync. during spring context initialization if finds bean id applicationeventmulticaster behaves async.

now want have both sync , async event publishers in application, because of events needs published sync. tried configure sync event multicaster using sysnctaskexecutor, cant find way inject asynceventpublisher's applicationeventpublisher property. spring configuration file below

<bean id="taskexecutor" class="org.springframework.scheduling.concurrent.threadpooltaskexecutor" destroy-method="shutdown"> <property name="corepoolsize" value="5" /> <property name="maxpoolsize" value="10" /> <property name="waitfortaskstocompleteonshutdown" value="true" /> </bean> <bean id="synctaskexecutor" class="org.springframework.core.task.synctaskexecutor" /> <bean id="customeventpublisher" class="x.spring.event.customeventpublisher" /> <bean id="customeventhandler" class="x.spring.event.customeventhandler" /> <bean id="eventsource" class="x.spring.event.eventsource" /> <bean id="responsehandler" class="x.spring.event.responsehandler" /> <bean id="synceventsource" class="x.spring.event.synceventsource" /> <bean id="applicationeventmulticaster" class="org.springframework.context.event.simpleapplicationeventmulticaster"> <property name="taskexecutor" ref="taskexecutor" /> </bean> <bean id="syncapplicationeventmulticaster" class="org.springframework.context.event.simpleapplicationeventmulticaster"> <property name="taskexecutor" ref="synctaskexecutor" /> </bean>

can help me out here ?

no, can't that, spring initapplicationeventmulticaster init one, , beanname must applicationeventmulticaster. can take 1 of below executor:

- org.springframework.core.task.synctaskexecutor - org.springframework.core.task.simpleasynctaskexecutor - own executor: org.springframework.scheduling.concurrent.threadpooltaskexecutor

any way, can modify org.springframework.context.event.simpleapplicationeventmulticaster add together logic, can command whether need sync/async

/** * initialize applicationeventmulticaster. * uses simpleapplicationeventmulticaster if none defined in context. * @see org.springframework.context.event.simpleapplicationeventmulticaster */ protected void initapplicationeventmulticaster() { configurablelistablebeanfactory beanfactory = getbeanfactory(); if (beanfactory.containslocalbean(application_event_multicaster_bean_name)) { this.applicationeventmulticaster = beanfactory.getbean(application_event_multicaster_bean_name, applicationeventmulticaster.class); if (logger.isdebugenabled()) { logger.debug("using applicationeventmulticaster [" + this.applicationeventmulticaster + "]"); } } else { this.applicationeventmulticaster = new simpleapplicationeventmulticaster(beanfactory); beanfactory.registersingleton(application_event_multicaster_bean_name, this.applicationeventmulticaster); if (logger.isdebugenabled()) { logger.debug("unable locate applicationeventmulticaster name '" + application_event_multicaster_bean_name + "': using default [" + this.applicationeventmulticaster + "]"); } } }

java spring asynchronous

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -