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 Shawn Smiley <ss...@yahoo.com> on 2006/02/13 22:39:57 UTC
Separate Database Connections on Different Threads
Is it possible to have one set of iBatis objects use different database connections on different threads?
My specific case is that I have a data import app running as a Windows Service. I have one thread that handles the actual data import of around 4000 records (within a single transaction) that periodically raises events to the main service thread that periodically updates a job queue table with the current status of the import process.
What's currently happening is that I get an initial status message written to the database and then no other status messages make it to the DB until the import transaction completes. I'm not sure if the status updates are being included in the transaction or not. I need them to be completely independent of the import Transaction.
I know that the status messages are being picked up by the service from the logging I'm doing (I see every status event in the logs).
Is what I'm trying to do possible and if so, what can I do to make this work?
Thanks,
Shawn
---------------------------------
Relax. Yahoo! Mail virus scanning helps detect nasty viruses!
Re: Separate Database Connections on Different Threads
Posted by Gilles Bayon <ib...@gmail.com>.
If you use the SqlMapper on diffrent thread you only need one SqlMapper
object.
The SqlMap or Dao context is per thread.
In your case if your 2 threads access the same table in a transaction, one
may block the other until the first finish.
On 2/14/06, Ron Grabowski <ro...@yahoo.com> wrote:
>
> Have you tried creating two SqlMapper objects and using each one in a
> seperate thread?
>
> // first thread
> SqlMapper sqlMap1 = createSqlMap("SqlMap1.config");
> IDataImporterDao dataImporterDao = new DataImporterDao(sqlMap1);
>
> // second thread
> SqlMapper sqlMap2 = createSqlMap("SqlMap2.config");
> IDataImporterDao dataImporterDao = new DataImporterDao(sqlMap2);
>
> Maybe you could use DataAccess' DaoManager to define two context and
> use each context on its own thread:
>
> // first thread
> DataManager thread1Manager = DaoManager.GetContext("Thread1");
> IDataImporterDao dataImportDao = thread1Manager.GetDao(
> typeof(IDataImporterDao)) as IDataImporterDao;
>
> // second thread
> DataManager thread2Manager = DaoManager.GetContext("Thread2");
> IDataImporterDao dataImportDao = thread2Manager.GetDao(
> typeof(IDataImporterDao)) as IDataImporterDao;
>
> --- Shawn Smiley <ss...@yahoo.com> wrote:
>
> > Is it possible to have one set of iBatis objects use different
> > database connections on different threads?
> >
> > My specific case is that I have a data import app running as a
> > Windows Service. I have one thread that handles the actual data
> > import of around 4000 records (within a single transaction) that
> > periodically raises events to the main service thread that
> > periodically updates a job queue table with the current status of the
> > import process.
> >
> > What's currently happening is that I get an initial status message
> > written to the database and then no other status messages make it to
> > the DB until the import transaction completes. I'm not sure if the
> > status updates are being included in the transaction or not. I need
> > them to be completely independent of the import Transaction.
> >
> > I know that the status messages are being picked up by the service
> > from the logging I'm doing (I see every status event in the logs).
> >
> > Is what I'm trying to do possible and if so, what can I do to make
> > this work?
> >
> > Thanks,
> > Shawn
> >
> >
> > ---------------------------------
> > Relax. Yahoo! Mail virus scanning helps detect nasty viruses!
>
>
Re: Separate Database Connections on Different Threads
Posted by Ron Grabowski <ro...@yahoo.com>.
Have you tried creating two SqlMapper objects and using each one in a
seperate thread?
// first thread
SqlMapper sqlMap1 = createSqlMap("SqlMap1.config");
IDataImporterDao dataImporterDao = new DataImporterDao(sqlMap1);
// second thread
SqlMapper sqlMap2 = createSqlMap("SqlMap2.config");
IDataImporterDao dataImporterDao = new DataImporterDao(sqlMap2);
Maybe you could use DataAccess' DaoManager to define two context and
use each context on its own thread:
// first thread
DataManager thread1Manager = DaoManager.GetContext("Thread1");
IDataImporterDao dataImportDao = thread1Manager.GetDao(
typeof(IDataImporterDao)) as IDataImporterDao;
// second thread
DataManager thread2Manager = DaoManager.GetContext("Thread2");
IDataImporterDao dataImportDao = thread2Manager.GetDao(
typeof(IDataImporterDao)) as IDataImporterDao;
--- Shawn Smiley <ss...@yahoo.com> wrote:
> Is it possible to have one set of iBatis objects use different
> database connections on different threads?
>
> My specific case is that I have a data import app running as a
> Windows Service. I have one thread that handles the actual data
> import of around 4000 records (within a single transaction) that
> periodically raises events to the main service thread that
> periodically updates a job queue table with the current status of the
> import process.
>
> What's currently happening is that I get an initial status message
> written to the database and then no other status messages make it to
> the DB until the import transaction completes. I'm not sure if the
> status updates are being included in the transaction or not. I need
> them to be completely independent of the import Transaction.
>
> I know that the status messages are being picked up by the service
> from the logging I'm doing (I see every status event in the logs).
>
> Is what I'm trying to do possible and if so, what can I do to make
> this work?
>
> Thanks,
> Shawn
>
>
> ---------------------------------
> Relax. Yahoo! Mail virus scanning helps detect nasty viruses!