Open asynchronous tasks in Java

Source: Internet
Author: User


It's usually written in the controller.

@ResponseBody
@RequestMapping ("/logoutcaigou")
public boolean Logoutcaigou (Modelandview Mav, @Param ("MemberID") Long MemberID, @Param ("OpenID") String openId) {

Saveloginlog (OpenId, MemberID, loginlog.logout); Store Log out logs
return true;
}

Turn on asynchronous logging
Initiates an asynchronous thread. , and perform tasks in the background. Once the task is opened, return directly
No need to wait for task execution to complete
private void Saveloginlog (final String openId, final long MemberID, int type) {

Executorservice exec = Executors.newsinglethreadexecutor (); To open an async singleton thread
Exec.execute (New Runnable () {
public void Run () {
Iloginlogservice.saveloginlog (OpenId, MemberID, Loginlog.login); Store login Log
}
});
Return
}




Service inside

@Override
@TradingDataSource (name = Datasources.write_wechat_datasource)
public boolean Saveloginlog (String openId, long MemberID, int type) throws Serviceexception {

Loginlog Loginlog = new Loginlog ();
Loginlog.setid (Sequenceutil.getseqnextval ("Seq_login_log"));
Loginlog.setopenid (OPENID);
Loginlog.setmemberid (MemberID);
Loginlog.setstate (type);
String key = Caigouconstant.cachekey_address_prefix + openId;
Cachemanagerdao.set (Key, "Beijing Beijing"); Save Detailed Address
Loginlog.setdevicemessage (Cachemanagerdao.get (key). ToString ());
Iloginlogdao.saveloginlog (Loginlog);
return true;
}



Open asynchronous tasks in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.