Monday, 15 February 2010

java - How to create independent thread using spring @Async -



java - How to create independent thread using spring @Async -

i using spring @async weblogic workmanager, spring version 3.2.2

web.xml :

<resource-ref> <res-ref-name>reportworkmanager</res-ref-name> <res-type>commonj.work.workmanager</res-type> <res-auth>container</res-auth> <res-sharing-scope>shareable</res-sharing-scope> </resource-ref>

weblogic.xml :

<work-manager> <name>reportworkmanager</name> <fair-share-request-class> <name>priority</name> <fair-share>100</fair-share> </fair-share-request-class> <min-threads-constraint> <name>minthreadcount</name> <count>15</count> </min-threads-constraint> <max-threads-constraint> <name>maxthreadcount</name> <count>25</count> </max-threads-constraint> <work-manager-shutdown-trigger> <max-stuck-thread-time>120</max-stuck-thread-time> <stuck-thread-count>25</stuck-thread-count> </work-manager-shutdown-trigger> </work-manager>

spirng configuration xml :

<bean id="reportworkmanagertaskexecutor" class="org.springframework.scheduling.commonj.workmanagertaskexecutor"> <property name="workmanagername" value="java:comp/env/reportworkmanager" /> </bean>

controller :

@requestmapping(value = "/publish", method = requestmethod.post) public marketingscenario publishreport(@requestbody final publishreportdto reportdto, final httpservletrequest request) throws exception { reportdto.setrequsername(dominowebutil.getloggedinusername(request)); reportengine.publishreport(reportdto); marketingscenario scenario = scenarioservice.findmarketingscenariobyid(reportdto.getscenarioid()); _logger.debug("job submitted , came out scenario id {}", reportdto.getscenarioid()); homecoming scenario; }

service :

@async(value = "reportworkmanagertaskexecutor") public void publishreport(final publishreportdto reportdto) { //some long run job }

whenever request coming fornt end , controller should intiate job calling service method , should returns response out waiting service job.

when @async not applied goes when applied, service thread getting killed because of request thread done.

please allow me know, using @async how create thread independent of request thread.

that independent thread may run 2 minutes or 20 minutes depends on input.

firstly, spring's docs state @async other default executor should annotated @async("otherexecutor") rather @async(value="otherexecutor").

also, don't think quite understand mean this:

when @async not applied goes when applied, service thread getting killed because of request thread done.

i'll asume mean runs ok on same thread. in case, makes perfect sense since you're running method synchronously.

java multithreading spring-mvc asynchronous workmanagers

No comments:

Post a Comment