i need send email in async way while saving data db.
my approach this.
//i have tried service layer annotating.but not worked. @enableasync class myservice{ public string savemethod(list listofdata){ mail.sendemailquote(listofdata); mail.sendemailworkflowtaskassignment(listofdata); mydao.savedata(listofdata); } } i need perform following methods in @async way. should put @enableasync annotation. not schedule related thing. happen when user click save button. application used flex spring blazeds. there no controller written self.
i have used @async annotation in code following 2 methods. in class call mail.
@async sendemailquote(listofdata){} @async sendemailworkflowtaskassignment(listofdata){} could me find should put @enableasync ?
enableasync used configuration , enable spring's asynchronous method execution capability, should not put on service or component class, should put on configuration class like:
@configuration @enableasync public class appconfig { } or more configuration of asyncexecutor like:
@configuration @enableasync public class appconfig implements asyncconfigurer {
@override public executor getasyncexecutor() { threadpooltaskexecutor executor = new threadpooltaskexecutor(); executor.setcorepoolsize(7); executor.setmaxpoolsize(42); executor.setqueuecapacity(11); executor.setthreadnameprefix("myexecutor-"); executor.initialize(); return executor; } } please refer it's java doc more details.
and tutorial followed, enableasync put above application class, extends asyncconfigurersupport asyncexecutor configuration:
@springbootapplication @enableasync public class application extends asyncconfigurersupport { public static void main(string[] args) { springapplication.run(application.class, args); } @override public executor getasyncexecutor() { threadpooltaskexecutor executor = new threadpooltaskexecutor(); executor.setcorepoolsize(2); executor.setmaxpoolsize(2); executor.setqueuecapacity(500); executor.setthreadnameprefix("githublookup-"); executor.initialize(); return executor; } }
Comments
Post a Comment