You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by De Gaetano Giuseppe <de...@PITAGORA.IT> on 2009/07/14 15:17:05 UTC

R: SqlMapClient multithread applications

Hi all,
after 2.5 years of production my application starts to have some problem.
Here is the error that I am experiencing

--- The error occurred while applying a parameter map.
--- Check the Foo.bar-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: Closed Connection

My application is performing some crud operation. In order to speed-up I decided to use an Hashtable to store SqlMapClient. The previous error appears if the number of running threads increases.

Otherwise I don't have any problem if I do not use any cache for SqlMapClient.

Any suggestion?

Thanks to all in advance
Giuseppe De Gaetano

-----Messaggio originale-----
Da: De Gaetano Giuseppe [mailto:degaetano@pitagora.it]
Inviato: venerdì 5 gennaio 2007 16.39
A: user-java@ibatis.apache.org; lmeadors@apache.org
Oggetto: R: SqlMapClient multithread applications

Hi, may be I wasn't clear enough.

With concurrency I meant2 threads each doing the following operations:
1. Start transaction.
2. insert row
3. insert another row
4. commit/rollback transaction

In this situation is the transaction isolation guaranteed?

> Is there any best practice? == speed up application end avoid loading every time the same config files

-----Messaggio originale-----
Da: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] Per conto di Larry Meadors
Inviato: venerdì 5 gennaio 2007 16.19
A: user-java@ibatis.apache.org
Oggetto: Re: SqlMapClient multithread applications

On 1/5/07, De Gaetano Giuseppe <de...@pitagora.it> wrote:
> If the application is multithread and each thread uses the same client will
> I have some problem?

Should be fine.

>
> Is the iBatis engine handling the concurrency or should I care?

What type of concurrency? If two threads update the same row in the
database, the last one in wins. iBATIS does not and will not likely
ever deal with that sort of thing.

> Is there any best practice?

Sorry if i am being dense, but for what?

Larry

________________________________________
Da: De Gaetano Giuseppe [mailto:degaetano@pitagora.it]
Inviato: venerdì 5 gennaio 2007 14.23
A: user-java@ibatis.apache.org
Oggetto: SqlMapClient multithread applications

Hi,
I am coding a java multithread application.
In my application I have the following object which needs to load the configuration files from a path not specified in the classpath end build an SqlMapClient.
The Hashtable is used for:
*       cache the clients and avoid the building of a new SqlMapClient every time;
*       speed up the application avoiding to load and parse the different config files every time

public class SqlMapClientConfig {
    private static Hashtable clients;

    static{
            clients = new Hashtable();
    }

    private SqlMapClientConfig(){

    }

    public Object clone() throws CloneNotSupportedException {
        throw new CloneNotSupportedException();
    }


    public static SqlMapClient getClient(String db, String usecase,) {
        String key =  db + "." + usecase;
        String path = "/dat/" + db + "/" + usecase;


        if(clients.containsKey(key))
            return (SqlMapClient) clients.get(key);
        else{
            Loader loader = new Loader(path);
            Resources.setDefaultClassLoader(loader);
            Reader reader = null;
        try {
             reader = Resources.getResourceAsReader (loader, "sql-map-config.xml");
         } catch (IOException e) {
             e.printStackTrace();
         }
         SqlMapClient sqlMap = null;

         sqlMap = (SqlMapClient) SqlMapClientBuilder.buildSqlMapClient(reader);

         clients.put(key,sqlMap);
         return sqlMap;
        }
    }
}

If the application is multithread and each thread uses the same client will I have some problem?
Is the iBatis engine handling the concurrency or should I care?

Is there any best practice?



---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


R: R: SqlMapClient multithread applications

Posted by De Gaetano Giuseppe <de...@PITAGORA.IT>.
Hi all,

debugging my application I discovered some sqlmapclient.setUserConnection() which causes the problem when the SqlMapClient is shared between many threads.

Thanks anyway for your help.
Giuseppe

-----Messaggio originale-----
Da: Larry Meadors [mailto:larry.meadors@gmail.com]
Inviato: martedì 14 luglio 2009 16.18
A: user-java@ibatis.apache.org
Oggetto: Re: R: SqlMapClient multithread applications

You can use a single sql map client to service many threads...if
that's your question. :)

Larry


On Tue, Jul 14, 2009 at 6:17 AM, De Gaetano
Giuseppe<de...@pitagora.it> wrote:
> Hi all,
> after 2.5 years of production my application starts to have some problem.
> Here is the error that I am experiencing
>
> --- The error occurred while applying a parameter map.
> --- Check the Foo.bar-InlineParameterMap.
> --- Check the statement (query failed).
> --- Cause: java.sql.SQLException: Closed Connection
>
> My application is performing some crud operation. In order to speed-up I decided to use an Hashtable to store SqlMapClient. The previous error appears if the number of running threads increases.
>
> Otherwise I don't have any problem if I do not use any cache for SqlMapClient.
>
> Any suggestion?
>
> Thanks to all in advance
> Giuseppe De Gaetano
>
> -----Messaggio originale-----
> Da: De Gaetano Giuseppe [mailto:degaetano@pitagora.it]
> Inviato: venerdì 5 gennaio 2007 16.39
> A: user-java@ibatis.apache.org; lmeadors@apache.org
> Oggetto: R: SqlMapClient multithread applications
>
> Hi, may be I wasn't clear enough.
>
> With concurrency I meant2 threads each doing the following operations:
> 1. Start transaction.
> 2. insert row
> 3. insert another row
> 4. commit/rollback transaction
>
> In this situation is the transaction isolation guaranteed?
>
>> Is there any best practice? == speed up application end avoid loading every time the same config files
>
> -----Messaggio originale-----
> Da: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] Per conto di Larry Meadors
> Inviato: venerdì 5 gennaio 2007 16.19
> A: user-java@ibatis.apache.org
> Oggetto: Re: SqlMapClient multithread applications
>
> On 1/5/07, De Gaetano Giuseppe <de...@pitagora.it> wrote:
>> If the application is multithread and each thread uses the same client will
>> I have some problem?
>
> Should be fine.
>
>>
>> Is the iBatis engine handling the concurrency or should I care?
>
> What type of concurrency? If two threads update the same row in the
> database, the last one in wins. iBATIS does not and will not likely
> ever deal with that sort of thing.
>
>> Is there any best practice?
>
> Sorry if i am being dense, but for what?
>
> Larry
>
> ________________________________________
> Da: De Gaetano Giuseppe [mailto:degaetano@pitagora.it]
> Inviato: venerdì 5 gennaio 2007 14.23
> A: user-java@ibatis.apache.org
> Oggetto: SqlMapClient multithread applications
>
> Hi,
> I am coding a java multithread application.
> In my application I have the following object which needs to load the configuration files from a path not specified in the classpath end build an SqlMapClient.
> The Hashtable is used for:
> *       cache the clients and avoid the building of a new SqlMapClient every time;
> *       speed up the application avoiding to load and parse the different config files every time
>
> public class SqlMapClientConfig {
>    private static Hashtable clients;
>
>    static{
>            clients = new Hashtable();
>    }
>
>    private SqlMapClientConfig(){
>
>    }
>
>    public Object clone() throws CloneNotSupportedException {
>        throw new CloneNotSupportedException();
>    }
>
>
>    public static SqlMapClient getClient(String db, String usecase,) {
>        String key =  db + "." + usecase;
>        String path = "/dat/" + db + "/" + usecase;
>
>
>        if(clients.containsKey(key))
>            return (SqlMapClient) clients.get(key);
>        else{
>            Loader loader = new Loader(path);
>            Resources.setDefaultClassLoader(loader);
>            Reader reader = null;
>        try {
>             reader = Resources.getResourceAsReader (loader, "sql-map-config.xml");
>         } catch (IOException e) {
>             e.printStackTrace();
>         }
>         SqlMapClient sqlMap = null;
>
>         sqlMap = (SqlMapClient) SqlMapClientBuilder.buildSqlMapClient(reader);
>
>         clients.put(key,sqlMap);
>         return sqlMap;
>        }
>    }
> }
>
> If the application is multithread and each thread uses the same client will I have some problem?
> Is the iBatis engine handling the concurrency or should I care?
>
> Is there any best practice?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


R: R: SqlMapClient multithread applications

Posted by De Gaetano Giuseppe <de...@pitagora.it>.
Hi, is what I am doing but I get this error. :-(
I use the hashtable in a factory that provides the needed SqlMapClient to the service.
Thanks
Giuseppe


I'll keep deep debugging the services.


-----Messaggio originale-----
Da: Larry Meadors [mailto:larry.meadors@gmail.com]
Inviato: martedì 14 luglio 2009 16.18
A: user-java@ibatis.apache.org
Oggetto: Re: R: SqlMapClient multithread applications

You can use a single sql map client to service many threads...if
that's your question. :)

Larry


On Tue, Jul 14, 2009 at 6:17 AM, De Gaetano
Giuseppe<de...@pitagora.it> wrote:
> Hi all,
> after 2.5 years of production my application starts to have some problem.
> Here is the error that I am experiencing
>
> --- The error occurred while applying a parameter map.
> --- Check the Foo.bar-InlineParameterMap.
> --- Check the statement (query failed).
> --- Cause: java.sql.SQLException: Closed Connection
>
> My application is performing some crud operation. In order to speed-up I decided to use an Hashtable to store SqlMapClient. The previous error appears if the number of running threads increases.
>
> Otherwise I don't have any problem if I do not use any cache for SqlMapClient.
>
> Any suggestion?
>
> Thanks to all in advance
> Giuseppe De Gaetano
>
> -----Messaggio originale-----
> Da: De Gaetano Giuseppe [mailto:degaetano@pitagora.it]
> Inviato: venerdì 5 gennaio 2007 16.39
> A: user-java@ibatis.apache.org; lmeadors@apache.org
> Oggetto: R: SqlMapClient multithread applications
>
> Hi, may be I wasn't clear enough.
>
> With concurrency I meant2 threads each doing the following operations:
> 1. Start transaction.
> 2. insert row
> 3. insert another row
> 4. commit/rollback transaction
>
> In this situation is the transaction isolation guaranteed?
>
>> Is there any best practice? == speed up application end avoid loading every time the same config files
>
> -----Messaggio originale-----
> Da: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] Per conto di Larry Meadors
> Inviato: venerdì 5 gennaio 2007 16.19
> A: user-java@ibatis.apache.org
> Oggetto: Re: SqlMapClient multithread applications
>
> On 1/5/07, De Gaetano Giuseppe <de...@pitagora.it> wrote:
>> If the application is multithread and each thread uses the same client will
>> I have some problem?
>
> Should be fine.
>
>>
>> Is the iBatis engine handling the concurrency or should I care?
>
> What type of concurrency? If two threads update the same row in the
> database, the last one in wins. iBATIS does not and will not likely
> ever deal with that sort of thing.
>
>> Is there any best practice?
>
> Sorry if i am being dense, but for what?
>
> Larry
>
> ________________________________________
> Da: De Gaetano Giuseppe [mailto:degaetano@pitagora.it]
> Inviato: venerdì 5 gennaio 2007 14.23
> A: user-java@ibatis.apache.org
> Oggetto: SqlMapClient multithread applications
>
> Hi,
> I am coding a java multithread application.
> In my application I have the following object which needs to load the configuration files from a path not specified in the classpath end build an SqlMapClient.
> The Hashtable is used for:
> *       cache the clients and avoid the building of a new SqlMapClient every time;
> *       speed up the application avoiding to load and parse the different config files every time
>
> public class SqlMapClientConfig {
>    private static Hashtable clients;
>
>    static{
>            clients = new Hashtable();
>    }
>
>    private SqlMapClientConfig(){
>
>    }
>
>    public Object clone() throws CloneNotSupportedException {
>        throw new CloneNotSupportedException();
>    }
>
>
>    public static SqlMapClient getClient(String db, String usecase,) {
>        String key =  db + "." + usecase;
>        String path = "/dat/" + db + "/" + usecase;
>
>
>        if(clients.containsKey(key))
>            return (SqlMapClient) clients.get(key);
>        else{
>            Loader loader = new Loader(path);
>            Resources.setDefaultClassLoader(loader);
>            Reader reader = null;
>        try {
>             reader = Resources.getResourceAsReader (loader, "sql-map-config.xml");
>         } catch (IOException e) {
>             e.printStackTrace();
>         }
>         SqlMapClient sqlMap = null;
>
>         sqlMap = (SqlMapClient) SqlMapClientBuilder.buildSqlMapClient(reader);
>
>         clients.put(key,sqlMap);
>         return sqlMap;
>        }
>    }
> }
>
> If the application is multithread and each thread uses the same client will I have some problem?
> Is the iBatis engine handling the concurrency or should I care?
>
> Is there any best practice?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: R: SqlMapClient multithread applications

Posted by Larry Meadors <la...@gmail.com>.
You can use a single sql map client to service many threads...if
that's your question. :)

Larry


On Tue, Jul 14, 2009 at 6:17 AM, De Gaetano
Giuseppe<de...@pitagora.it> wrote:
> Hi all,
> after 2.5 years of production my application starts to have some problem.
> Here is the error that I am experiencing
>
> --- The error occurred while applying a parameter map.
> --- Check the Foo.bar-InlineParameterMap.
> --- Check the statement (query failed).
> --- Cause: java.sql.SQLException: Closed Connection
>
> My application is performing some crud operation. In order to speed-up I decided to use an Hashtable to store SqlMapClient. The previous error appears if the number of running threads increases.
>
> Otherwise I don't have any problem if I do not use any cache for SqlMapClient.
>
> Any suggestion?
>
> Thanks to all in advance
> Giuseppe De Gaetano
>
> -----Messaggio originale-----
> Da: De Gaetano Giuseppe [mailto:degaetano@pitagora.it]
> Inviato: venerdì 5 gennaio 2007 16.39
> A: user-java@ibatis.apache.org; lmeadors@apache.org
> Oggetto: R: SqlMapClient multithread applications
>
> Hi, may be I wasn't clear enough.
>
> With concurrency I meant2 threads each doing the following operations:
> 1. Start transaction.
> 2. insert row
> 3. insert another row
> 4. commit/rollback transaction
>
> In this situation is the transaction isolation guaranteed?
>
>> Is there any best practice? == speed up application end avoid loading every time the same config files
>
> -----Messaggio originale-----
> Da: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] Per conto di Larry Meadors
> Inviato: venerdì 5 gennaio 2007 16.19
> A: user-java@ibatis.apache.org
> Oggetto: Re: SqlMapClient multithread applications
>
> On 1/5/07, De Gaetano Giuseppe <de...@pitagora.it> wrote:
>> If the application is multithread and each thread uses the same client will
>> I have some problem?
>
> Should be fine.
>
>>
>> Is the iBatis engine handling the concurrency or should I care?
>
> What type of concurrency? If two threads update the same row in the
> database, the last one in wins. iBATIS does not and will not likely
> ever deal with that sort of thing.
>
>> Is there any best practice?
>
> Sorry if i am being dense, but for what?
>
> Larry
>
> ________________________________________
> Da: De Gaetano Giuseppe [mailto:degaetano@pitagora.it]
> Inviato: venerdì 5 gennaio 2007 14.23
> A: user-java@ibatis.apache.org
> Oggetto: SqlMapClient multithread applications
>
> Hi,
> I am coding a java multithread application.
> In my application I have the following object which needs to load the configuration files from a path not specified in the classpath end build an SqlMapClient.
> The Hashtable is used for:
> *       cache the clients and avoid the building of a new SqlMapClient every time;
> *       speed up the application avoiding to load and parse the different config files every time
>
> public class SqlMapClientConfig {
>    private static Hashtable clients;
>
>    static{
>            clients = new Hashtable();
>    }
>
>    private SqlMapClientConfig(){
>
>    }
>
>    public Object clone() throws CloneNotSupportedException {
>        throw new CloneNotSupportedException();
>    }
>
>
>    public static SqlMapClient getClient(String db, String usecase,) {
>        String key =  db + "." + usecase;
>        String path = "/dat/" + db + "/" + usecase;
>
>
>        if(clients.containsKey(key))
>            return (SqlMapClient) clients.get(key);
>        else{
>            Loader loader = new Loader(path);
>            Resources.setDefaultClassLoader(loader);
>            Reader reader = null;
>        try {
>             reader = Resources.getResourceAsReader (loader, "sql-map-config.xml");
>         } catch (IOException e) {
>             e.printStackTrace();
>         }
>         SqlMapClient sqlMap = null;
>
>         sqlMap = (SqlMapClient) SqlMapClientBuilder.buildSqlMapClient(reader);
>
>         clients.put(key,sqlMap);
>         return sqlMap;
>        }
>    }
> }
>
> If the application is multithread and each thread uses the same client will I have some problem?
> Is the iBatis engine handling the concurrency or should I care?
>
> Is there any best practice?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org