Thanks for suggestion
Taking the createinjector out of that method (using a singleton) save so 
much time...

But i suppose the original question is still valid (but now not so 
important), why 2 different be behavior of the previous code?

Il giorno martedì 27 marzo 2018 19:39:56 UTC+2, Tavian Barnes ha scritto:
>
> Guice.createInjector() is slow, is it possible to avoid calling it in a 
> loop?  E.g. by creating the injector once outside the loop and only calling 
> .getInstance() inside the loop?
>
> On Tuesday, 27 March 2018 04:51:00 UTC-4, [email protected] wrote:
>>
>> I have a strange performance behavior with google guice in my project
>>
>> My company have a project that use google guice and groovy.
>> I have to admin: I do not know well google guice (it's been chosen from 
>> other than me)
>>
>> i have this case, it's not easy to explain, let's try
>>
>> I have this classes
>>
>> a groovy class with this method (Class A)
>>
>>  public Integer resMesiFatturazionePerAnno(Integer anno) {
>>        [some code]
>>         def bollelett = getListByQuery(BollaLetture, """select bl.* from 
>> bolla_letture bl, bolla b, fat where
>>                                                         
>> b.id_centro_subentro = ? and
>>                                                         b.id_fat = fat.id 
>> and
>>                                                         fat.dt>=? and 
>> fat.dt<= ? and
>>                                                         bl.id_bolla = 
>> b.id
>>                                                         ORDER by bl.dt asc
>>                                                         """, 
>> getCentroSubentroId(), inizioAnno, fineAnno)
>>        [some code]
>>     }
>>
>>
>> other groovy class with this method (CLASS B)
>>
>> public <T extends BOIf> List<T> getListByQuery(Class<T> c, String query, 
>> Object... list) throws java.lang.Exception {
>>         [some code]
>>         for (Map h : this.queryToMapList(query, list)) {
>>             long test1 = System.currentTimeMillis();            
>>             T bo = Guice.createInjector(new BillModule(), new 
>> CacheModule()).getInstance(c);
>>              System.out.println("ciclomap: "  + 
>> (System.currentTimeMillis() - test1));
>>             [some code]       
>>          }
>>         System.out.println("getListByQuery: " + 
>> (System.currentTimeMillis()-test));
>>         return l;
>>     } 
>>
>> if you see, the resMesiFatturazionePerAnno method use the getListByQuery 
>> method, and getListByQuery have Guice createInjector inside
>> resMesiFatturazionePerAnno is invoked from codes inside a batch script, 
>> so invoken 20/30.000 times over different instance of CLASS A
>>
>> depends from where i invoke resMesiFatturazionePerAnno in some case i can 
>> see that this lines
>>
>> long test1 = System.currentTimeMillis();            
>> T bo = Guice.createInjector(new BillModule(), new 
>> CacheModule()).getInstance(c);
>> System.out.println("ciclomap: "  + (System.currentTimeMillis() - test1));
>>
>> take 10 milliseconds to executes, but if invoked from other circumstance 
>> it take 20ms to executes  (in my case 10ms more for EVERY time the 
>> getListByQuery it's called it's really big damage)
>>
>> Can someone help me to find out why this behaviour?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/b8cb8183-50d5-4d39-8d00-68f97afd3557%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to