You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by jmsandy <jm...@gmail.com> on 2009/08/12 15:45:25 UTC

Help in MultiThreads

Hi,

I need much help from you. I need to optimize a query and the only possible
way and run parallel accesses.

I am consulting divided into parts to run.

The scenario I have is:
1) I make the call to a Webservice which routines should be run.
2) I did call and got error with Threads.
3) I tried with asynchronous methods and got error.
4) The error I am getting is:

  Message="WebSessionStore: Could not obtain reference to HttpContext"
  Source="IBatisNet.DataMapper"
  StackTrace:
       at
IBatisNet.DataMapper.SessionStore.WebSessionStore.ObtainSessionContext()
       at
IBatisNet.DataMapper.SessionStore.WebSessionStore.get_LocalSession()
       at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String
statementName, Object parameterObject)

How do I make several simultaneous queries in Ibatis. Please pass me an
example.

Thanks. 


-- 
View this message in context: http://www.nabble.com/Help-in-MultiThreads-tp24936820p24936820.html
Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.


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


RE: Help in MultiThreads

Posted by Chen Jin <cj...@helpathome.com>.
Hi,

I personally encountered this issue several times either in 1.6.0 or 1.6.1.
There were several archived discussion for this issue. The reason is when
you create the DataMapper instance, the Ibatis.Net will see if the thread
(which run the code to create the DataMapper) has the so called
"HttpContext". If so the Ibatis.net will use that context as the session
store, otherwise it will use the thread's context (not exactly true, but you
can read the source code if you want). So when you do the multithreading,
definitely you will use new thread not directly run this ASP.NET code so
DataMapper cannot get its session store from the thread. So I have two
solutions for this issue

1. Every time you call the DataMapper, get a new instance rather than the
traditional singleton solution. This is very simple, do not need to change
your code too much, but with bad performance, especially when you have a log
of DB calls.
2. Change the code you creating the DataMapper instance, create a new thread
to create that to force Ibatis.Net do not use the HttpContext.

Hope this helps! 

Chen 

-----Original Message-----
From: jmsandy [mailto:jmsandy@gmail.com] 
Sent: Wednesday, August 12, 2009 8:45 AM
To: user-cs@ibatis.apache.org
Subject: Help in MultiThreads


Hi,

I need much help from you. I need to optimize a query and the only possible
way and run parallel accesses.

I am consulting divided into parts to run.

The scenario I have is:
1) I make the call to a Webservice which routines should be run.
2) I did call and got error with Threads.
3) I tried with asynchronous methods and got error.
4) The error I am getting is:

  Message="WebSessionStore: Could not obtain reference to HttpContext"
  Source="IBatisNet.DataMapper"
  StackTrace:
       at
IBatisNet.DataMapper.SessionStore.WebSessionStore.ObtainSessionContext()
       at
IBatisNet.DataMapper.SessionStore.WebSessionStore.get_LocalSession()
       at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String
statementName, Object parameterObject)

How do I make several simultaneous queries in Ibatis. Please pass me an
example.

Thanks. 


-- 
View this message in context:
http://www.nabble.com/Help-in-MultiThreads-tp24936820p24936820.html
Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.


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





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


Re: Help in MultiThreads

Posted by Andrea Tassinari <an...@i-mconsulting.com>.
Hi,

try to set the mapper's sessionstore to hybrid.

//initialise ISqlMapper...
//..
_mapper.SessionStore = new HybridWebThreadSessionStore(_mapper.Id);

andrea

jmsandy wrote:
> Hi,
> 
> I need much help from you. I need to optimize a query and the only possible
> way and run parallel accesses.
> 
> I am consulting divided into parts to run.
> 
> The scenario I have is:
> 1) I make the call to a Webservice which routines should be run.
> 2) I did call and got error with Threads.
> 3) I tried with asynchronous methods and got error.
> 4) The error I am getting is:
> 
>   Message="WebSessionStore: Could not obtain reference to HttpContext"
>   Source="IBatisNet.DataMapper"
>   StackTrace:
>        at
> IBatisNet.DataMapper.SessionStore.WebSessionStore.ObtainSessionContext()
>        at
> IBatisNet.DataMapper.SessionStore.WebSessionStore.get_LocalSession()
>        at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String
> statementName, Object parameterObject)
> 
> How do I make several simultaneous queries in Ibatis. Please pass me an
> example.
> 
> Thanks. 
> 
> 

-- 
AndreaT

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


Re: Help in MultiThreads

Posted by Andrea Tassinari <an...@i-mconsulting.com>.
:-))))))

http://quartznet.sourceforge.net/

Andrea

Juan Pablo Araya wrote:
> Google Quartz.Net:
> 
> Daily Nude - Updated Daily @ Quartz.net
> Hegre's images are so profound; his subjects so perfect, so pure, and
> so unbelievably beautiful, they prance about as emblems of youthful
> perfection. ...
> www.quartz.net/
> 
> Thanks for the page!!!!!
> 
> hehe greetings!
> 
> 
> 
> On Wed, Aug 12, 2009 at 10:41 AM, Andrea
> Tassinari<an...@i-mconsulting.com> wrote:
>>
>> Juan Pablo Araya wrote:
>>
>>> In our case, we used iBatis in web and inside a workflow managed by
>>> the workflowruntime (that runs in another thread), that's a very
>>> similar problem in the threaded execution.
>> same issue except we run Quartz.Net jobs calling mapper methods.
>>
>>
>> --
>> AndreaT
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-cs-help@ibatis.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-cs-help@ibatis.apache.org
> 
> 

-- 
AndreaT

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


Re: Help in MultiThreads

Posted by Juan Pablo Araya <ju...@gmail.com>.
Google Quartz.Net:

Daily Nude - Updated Daily @ Quartz.net
Hegre's images are so profound; his subjects so perfect, so pure, and
so unbelievably beautiful, they prance about as emblems of youthful
perfection. ...
www.quartz.net/

Thanks for the page!!!!!

hehe greetings!



On Wed, Aug 12, 2009 at 10:41 AM, Andrea
Tassinari<an...@i-mconsulting.com> wrote:
>
>
> Juan Pablo Araya wrote:
>
>> In our case, we used iBatis in web and inside a workflow managed by
>> the workflowruntime (that runs in another thread), that's a very
>> similar problem in the threaded execution.
>
> same issue except we run Quartz.Net jobs calling mapper methods.
>
>
> --
> AndreaT
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-cs-help@ibatis.apache.org
>
>

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


Re: Help in MultiThreads

Posted by Andrea Tassinari <an...@i-mconsulting.com>.

Juan Pablo Araya wrote:

> In our case, we used iBatis in web and inside a workflow managed by
> the workflowruntime (that runs in another thread), that's a very
> similar problem in the threaded execution.

same issue except we run Quartz.Net jobs calling mapper methods.


-- 
AndreaT

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


Re: Help in MultiThreads

Posted by Juan Pablo Araya <ju...@gmail.com>.
The id is a property of the mapper. Once yo do

ISqlMapper sqlMapper = Mapper.Instance();

You get the id automagically.

The other solution is given by  Chen Jin, BUT the first option is
extremelly bad in performance. The new instance of the mapper makes a
re-configuration of the mapper with the XML files, so if you do X
queries, you're just re-configuring X times the mapper (as far as I
understand on my experience). Don't know about the second solution.

Try with

ISqlMapper sqlMapper = Mapper.Instance();
sqlMapper.SessionStore = new HybridWebThreadSessionStore(sqlMapper.Id);
sqlMapper.TheiBatisMethods()

instead of

Instance().TheiBatisMethods()

TheiBatisMethods() = Insert(),  Delete(), Update(), QueryForList<T>(), etc.


In our case, we used iBatis in web and inside a workflow managed by
the workflowruntime (that runs in another thread), that's a very
similar problem in the threaded execution.

Greetings!



On Wed, Aug 12, 2009 at 10:11 AM, jmsandy<jm...@gmail.com> wrote:
>
>
> Hi friend,
>
> The problem is that I can not get the id. I have this attribute, as I do?
>
> Is there any way static.
>
> Thanks for the tip.
>
>
> Juan Pablo Araya wrote:
>>
>> I had the same problem a year ago. The error occurred because you run
>> ibatis in different threads. In my case, I just used
>>
>>             ISqlMapper sqlMapper = Mapper.Instance();
>>             sqlMapper.SessionStore = new
>> HybridWebThreadSessionStore(sqlMapper.Id);
>>
>> in every iBatis call and then it worked.
>>
>> Hope this work for you. Greetings and sorry for my poor english!
>>
>> On Wed, Aug 12, 2009 at 9:45 AM, jmsandy<jm...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> I need much help from you. I need to optimize a query and the only
>>> possible
>>> way and run parallel accesses.
>>>
>>> I am consulting divided into parts to run.
>>>
>>> The scenario I have is:
>>> 1) I make the call to a Webservice which routines should be run.
>>> 2) I did call and got error with Threads.
>>> 3) I tried with asynchronous methods and got error.
>>> 4) The error I am getting is:
>>>
>>>  Message="WebSessionStore: Could not obtain reference to HttpContext"
>>>  Source="IBatisNet.DataMapper"
>>>  StackTrace:
>>>       at
>>> IBatisNet.DataMapper.SessionStore.WebSessionStore.ObtainSessionContext()
>>>       at
>>> IBatisNet.DataMapper.SessionStore.WebSessionStore.get_LocalSession()
>>>       at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String
>>> statementName, Object parameterObject)
>>>
>>> How do I make several simultaneous queries in Ibatis. Please pass me an
>>> example.
>>>
>>> Thanks.
>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Help-in-MultiThreads-tp24936820p24936820.html
>>> Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
>>> For additional commands, e-mail: user-cs-help@ibatis.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-cs-help@ibatis.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Help-in-MultiThreads-tp24936820p24937420.html
> Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-cs-help@ibatis.apache.org
>
>

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


Re: Help in MultiThreads

Posted by jmsandy <jm...@gmail.com>.
	
Hi friend,

The problem is that I can not get the id. I have this attribute, as I do?

Is there any way static.

Thanks for the tip.


Juan Pablo Araya wrote:
> 
> I had the same problem a year ago. The error occurred because you run
> ibatis in different threads. In my case, I just used
> 
>             ISqlMapper sqlMapper = Mapper.Instance();
>             sqlMapper.SessionStore = new
> HybridWebThreadSessionStore(sqlMapper.Id);
> 
> in every iBatis call and then it worked.
> 
> Hope this work for you. Greetings and sorry for my poor english!
> 
> On Wed, Aug 12, 2009 at 9:45 AM, jmsandy<jm...@gmail.com> wrote:
>>
>> Hi,
>>
>> I need much help from you. I need to optimize a query and the only
>> possible
>> way and run parallel accesses.
>>
>> I am consulting divided into parts to run.
>>
>> The scenario I have is:
>> 1) I make the call to a Webservice which routines should be run.
>> 2) I did call and got error with Threads.
>> 3) I tried with asynchronous methods and got error.
>> 4) The error I am getting is:
>>
>>  Message="WebSessionStore: Could not obtain reference to HttpContext"
>>  Source="IBatisNet.DataMapper"
>>  StackTrace:
>>       at
>> IBatisNet.DataMapper.SessionStore.WebSessionStore.ObtainSessionContext()
>>       at
>> IBatisNet.DataMapper.SessionStore.WebSessionStore.get_LocalSession()
>>       at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String
>> statementName, Object parameterObject)
>>
>> How do I make several simultaneous queries in Ibatis. Please pass me an
>> example.
>>
>> Thanks.
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Help-in-MultiThreads-tp24936820p24936820.html
>> Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-cs-help@ibatis.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-cs-help@ibatis.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Help-in-MultiThreads-tp24936820p24937420.html
Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.


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


Re: Help in MultiThreads

Posted by jmsandy <jm...@gmail.com>.
Hello friends,

I am very grateful for the help yesterday. Was not detected this
attribute(id) because was with an older version of Ibatis.

What happens now is: I have that consultat with the same instruction,
passing just different Hashtable as parameter.
	
When I move the same object, all the threads run correctly. But when I step
objects (Hashtable) different is the following error:

Data conversion error.

Use the Informix.

Thank you. 


Juan Pablo Araya wrote:
> 
> I had the same problem a year ago. The error occurred because you run
> ibatis in different threads. In my case, I just used
> 
>             ISqlMapper sqlMapper = Mapper.Instance();
>             sqlMapper.SessionStore = new
> HybridWebThreadSessionStore(sqlMapper.Id);
> 
> in every iBatis call and then it worked.
> 
> Hope this work for you. Greetings and sorry for my poor english!
> 
> On Wed, Aug 12, 2009 at 9:45 AM, jmsandy<jm...@gmail.com> wrote:
>>
>> Hi,
>>
>> I need much help from you. I need to optimize a query and the only
>> possible
>> way and run parallel accesses.
>>
>> I am consulting divided into parts to run.
>>
>> The scenario I have is:
>> 1) I make the call to a Webservice which routines should be run.
>> 2) I did call and got error with Threads.
>> 3) I tried with asynchronous methods and got error.
>> 4) The error I am getting is:
>>
>>  Message="WebSessionStore: Could not obtain reference to HttpContext"
>>  Source="IBatisNet.DataMapper"
>>  StackTrace:
>>       at
>> IBatisNet.DataMapper.SessionStore.WebSessionStore.ObtainSessionContext()
>>       at
>> IBatisNet.DataMapper.SessionStore.WebSessionStore.get_LocalSession()
>>       at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String
>> statementName, Object parameterObject)
>>
>> How do I make several simultaneous queries in Ibatis. Please pass me an
>> example.
>>
>> Thanks.
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Help-in-MultiThreads-tp24936820p24936820.html
>> Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-cs-help@ibatis.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-cs-help@ibatis.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Help-in-MultiThreads-tp24936820p24954614.html
Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.


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


Re: Help in MultiThreads

Posted by Juan Pablo Araya <ju...@gmail.com>.
I had the same problem a year ago. The error occurred because you run
ibatis in different threads. In my case, I just used

            ISqlMapper sqlMapper = Mapper.Instance();
            sqlMapper.SessionStore = new
HybridWebThreadSessionStore(sqlMapper.Id);

in every iBatis call and then it worked.

Hope this work for you. Greetings and sorry for my poor english!

On Wed, Aug 12, 2009 at 9:45 AM, jmsandy<jm...@gmail.com> wrote:
>
> Hi,
>
> I need much help from you. I need to optimize a query and the only possible
> way and run parallel accesses.
>
> I am consulting divided into parts to run.
>
> The scenario I have is:
> 1) I make the call to a Webservice which routines should be run.
> 2) I did call and got error with Threads.
> 3) I tried with asynchronous methods and got error.
> 4) The error I am getting is:
>
>  Message="WebSessionStore: Could not obtain reference to HttpContext"
>  Source="IBatisNet.DataMapper"
>  StackTrace:
>       at
> IBatisNet.DataMapper.SessionStore.WebSessionStore.ObtainSessionContext()
>       at
> IBatisNet.DataMapper.SessionStore.WebSessionStore.get_LocalSession()
>       at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String
> statementName, Object parameterObject)
>
> How do I make several simultaneous queries in Ibatis. Please pass me an
> example.
>
> Thanks.
>
>
> --
> View this message in context: http://www.nabble.com/Help-in-MultiThreads-tp24936820p24936820.html
> Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-cs-help@ibatis.apache.org
>
>

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