Remotely call action in grails and grails call action

Source: Internet
Author: User
Tags grails

Remotely call action in grails and grails call action

When performing a program similar to batch processing, if you need to save a large number of records in an action, this will cause the database session in grails to exceed the load, resulting in OOM.

This is because all the modifications made to the data in a request are saved in the database session of the request. The database session will be released only after the request ends, in this way, if the number of data records modified in this request is too large, OOM will occur.

We use the mongodb database and grails mongodb plugin. Even if we use the underlying link of mongodb In This plugin for operations, OOM still occurs.

Therefore, we want to make each request retain only a small amount of modification data in the database session, which is equivalent to writing the modification of specific data in another action. The sample code is as follows:

    def updateData(){        println "classId:${params.classId} usersId:${params.usersId}"        render "ok"    }

 

The method to call this action is:

println dataService.remoteCall(request, g.createLink(action: 'updateData', params: [classId:"test1", usersId:'usersIdxxx']))

The key to implementation here is the function implementation of dataService. remoteCall, which is as follows:

/*** Get the protocol and Host IP url without/* For example: * http: // localhost: 9090/blog/bkoff/testCaculateUserExedCount * returned: http: /localhost: 9090 * @ param request * @ return */private String getHostUrl (request) {String requestUrl = request. requestURL String seperator = ": //" int index = requestUrl. indexOf (": //") index = requestUrl. indexOf ("/", index + seperator. length () return requestUrl. substring (0, index)}/*** call a method remotely, you can create * @ param request * @ param actionUrl * @ return */def String remoteCall (request, actionUrl) {def hostUrl = getHostUrl (request) in createLink mode) def url = new URL (hostUrl + actionUrl) return url. text}

 

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.