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