Dear Restlet mailing list,

Do you think that the JacksonRepresentation could be expensive in
terms of performance if I create one inside my ServerResource classes?
Because I have very little knowledge of Restlet internatls, I don't
know if a new ServerResource is create every time a client connects to
the resource or if the same object is reused multiple times.

if a new instance of ServerResource is made every time there's a
connection then there should be a performance problem when using a
JacksonRepresentation.

I was digging in the source code and I found that everytime a
JacksonRepresentation is constructed a new ObjectMapper and a new
JsonFactory is created the first time i call getObject(). This page
states that they should be reused when possible
http://wiki.fasterxml.com/JacksonBestPracticesPerformance to achieve
the best performance

What should be the more performance-aware metodology to speed things
up in a restlet application? I was thinking about creating all the
JsonRepresentation objects once in my Application constructor and
getting them in the ServerResource classes through java reflection.
Something like this:

public JacksonRepresentation<MyType>
retrieveJacksonRepForMyType(Application app) {
        JacksonRepresentation<MyType> jRep = null;
        Method jRepMethod;
        try {
                jRepMethod = app.getClass().getMethod("getJacksonRepMyType");
                jRep = (JacksonRepresentation<MyType)jRepMethod.invoke(app);
        } catch (NoSuchMethodException | SecurityException | 
IllegalAccessException |
                        IllegalArgumentException | InvocationTargetException e) 
{
                e.printStackTrace();
        }       
        return jRep;
}

any other suggestions?

greetings,
Pier Luigi

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3044375

Reply via email to