You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christian Stalp <st...@imbei.uni-mainz.de> on 2006/01/06 13:50:32 UTC
Single Thread is deprecated?
Hello out there,
I want to build a servelt which access a database. To avoid
race-conditions and to realize synchronous access, I decited to make a
"Singe Thread" Servlet. But Eclipse told me that this is no longer a
usable code.
So what can I do else?
Thank you...
Gruss Christian
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Single Thread is deprecated?
Posted by Michael Echerer <me...@tngtech.com>.
Remy Maucherat wrote:
> On 1/6/06, Michael Echerer <me...@tngtech.com> wrote:
>
>>In worst case you won't even achieve what you want using single thread
>>mode because according to the servlet specification servlet containers
>>are free to pool servlets, if it implements SingleThreadModel. Hence you
>>could have multiple pooled instances that be no means guarantee an
>>synchronized access to your database in case of simultaneous requests
>>hitting different instances.
>>
>>So SingleThreadModel is deprecated for good reason, since servlet spec
>>2.4 and also for 2.5. You are better of synchronizing yourself. Don't
>>rely on SingleThreadModel as an easy way to get around multithreading
>>issues.
>
>
> Nice, but completely wrong. STM in Tomcat uses an instance pool which
> allows having a minimal impact (something like 5%), and it will
> perform much better than syncing, unless the said sync is trivial.
Completely wrong? Actually taken from servlet spec 2.5 draft, but I
guess it's not changed since 2.4.
"SRV.2.2.1 Note About The Single Thread Model
The use of the SingleThreadModel interface guarantees that only one
thread at a
time will execute in a given servlet instance’s service method. It is
important to
note that this guarantee only applies to each servlet instance, since
the container may
choose to pool such objects. Objects that are accessible to more than
one servlet
instance at a time, such as instances of HttpSession, may be available
at any particular
time to multiple servlets, including those that implement SingleThreadModel.
It is recommended that a developer take other means to resolve those
issues instead
of implementing this interface, such as avoiding the usage of an
instance variable or
synchronizing the block of the code accessing those resources. The
SingleThreadModel Interface is deprecated in this version of the
specification."
Probably I mis-understood what "guarantee only applies to 'each' servlet
instance, since the container may choose to pool such objects".
In how far this is good for performance reasons, I cannot judge, never
tried for above reasons.
>
> The reason this is deprecated is because some people thought it would
> solve all their syncing problems, while it doesn't address many things
> (like session access).
true indeed, that's why I warned to use single thread model for an easy
cure for all multithreading issues (especially if a DB access is intendend).
Cheers,
Michael
>
> --
> xxxxxxxxxxxxxxxxxxxxxxxxx
> Rémy Maucherat
> Developer & Consultant
> JBoss Group (Europe) SàRL
> xxxxxxxxxxxxxxxxxxxxxxxxx
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Single Thread is deprecated?
Posted by Christian Stalp <st...@imbei.uni-mainz.de>.
Remy Maucherat schrieb:
>Nice, but completely wrong. STM in Tomcat uses an instance pool which
>allows having a minimal impact (something like 5%), and it will
>perform much better than syncing, unless the said sync is trivial.
>
>The reason this is deprecated is because some people thought it would
>solve all their syncing problems, while it doesn't address many things
>(like session access).
>
>
>
In my case the session-management will be realized by a front-servlet.
This servlet accept all the input of the user. Package this input into
JDOM-Objects and send this object to this "single threaded" servlet.
This servlets does nothing but to access the database.
Gruss Christian
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Single Thread is deprecated?
Posted by Remy Maucherat <re...@gmail.com>.
On 1/6/06, Michael Echerer <me...@tngtech.com> wrote:
> In worst case you won't even achieve what you want using single thread
> mode because according to the servlet specification servlet containers
> are free to pool servlets, if it implements SingleThreadModel. Hence you
> could have multiple pooled instances that be no means guarantee an
> synchronized access to your database in case of simultaneous requests
> hitting different instances.
>
> So SingleThreadModel is deprecated for good reason, since servlet spec
> 2.4 and also for 2.5. You are better of synchronizing yourself. Don't
> rely on SingleThreadModel as an easy way to get around multithreading
> issues.
Nice, but completely wrong. STM in Tomcat uses an instance pool which
allows having a minimal impact (something like 5%), and it will
perform much better than syncing, unless the said sync is trivial.
The reason this is deprecated is because some people thought it would
solve all their syncing problems, while it doesn't address many things
(like session access).
--
xxxxxxxxxxxxxxxxxxxxxxxxx
Rémy Maucherat
Developer & Consultant
JBoss Group (Europe) SàRL
xxxxxxxxxxxxxxxxxxxxxxxxx
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Single Thread is deprecated?
Posted by Michael Echerer <me...@tngtech.com>.
Christian Stalp wrote:
> Hello out there,
> I want to build a servelt which access a database. To avoid
> race-conditions and to realize synchronous access, I decited to make a
> "Singe Thread" Servlet. But Eclipse told me that this is no longer a
> usable code.
Usually the best solution is to synchronize just the part that accesses
the single resource (the DB) instead of using single thread.
In worst case you won't even achieve what you want using single thread
mode because according to the servlet specification servlet containers
are free to pool servlets, if it implements SingleThreadModel. Hence you
could have multiple pooled instances that be no means guarantee an
synchronized access to your database in case of simultaneous requests
hitting different instances.
So SingleThreadModel is deprecated for good reason, since servlet spec
2.4 and also for 2.5. You are better of synchronizing yourself. Don't
rely on SingleThreadModel as an easy way to get around multithreading
issues.
In case you have different code parts accessing your DB or various
clients, it might not even help to just sync one servlet. You might even
have to set database transaction isolation level to fit your needs for
your DB connections. Most DBs have "read-committed" by default, but it
might be that you need isolation level up to "synchronized". Depends on
your use case...
Cheers
Michael
>
> So what can I do else?
>
> Thank you...
>
> Gruss Christian
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Single Thread is deprecated?
Posted by David Kerber <dc...@verizon.net>.
Christian Stalp wrote:
> Remy Maucherat wrote:
>
>> It's deprecated because it is confusing, but it is actually very
>> useful performance wise in some cases, since it does pooling. I will
>> make sure this feature remains available in the future.
>>
>>
>>
> That means, I still can use it?! Deprecated is not prohibited!?!! Is
> there any alternative for such purposes?
Deprecated does not mean prohibited; it just means not recommended.
Frequently this is because its functionality is being replaced by a
newer method, but there can be other reasons as well.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Single Thread is deprecated?
Posted by Wade Chandler <hw...@yahoo.com>.
--- Christian Stalp <st...@imbei.uni-mainz.de> wrote:
> Remy Maucherat wrote:
>
> >It's deprecated because it is confusing, but it is
> actually very
> >useful performance wise in some cases, since it
> does pooling. I will
> >make sure this feature remains available in the
> future.
> >
> >
> >
> That means, I still can use it?! Deprecated is not
> prohibited!?!! Is
> there any alternative for such purposes?
>
> Gruss Christian
Deprecated only means the feature is not guarenteed to
be around in future releases, so you shouldn't be
upset if one day it is gone in another version. It
doesn't mean you can't use it. Sometimes APIs get
deprecated before their replacements are even added
(when they're getting a replacement).
For a simple definition of the word:
http://www.webopedia.com/TERM/D/deprecated.html
Wade
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Single Thread is deprecated?
Posted by Christian Stalp <st...@imbei.uni-mainz.de>.
Remy Maucherat wrote:
>It's deprecated because it is confusing, but it is actually very
>useful performance wise in some cases, since it does pooling. I will
>make sure this feature remains available in the future.
>
>
>
That means, I still can use it?! Deprecated is not prohibited!?!! Is
there any alternative for such purposes?
Gruss Christian
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Single Thread is deprecated?
Posted by Remy Maucherat <re...@gmail.com>.
On 1/6/06, Christian Stalp <st...@imbei.uni-mainz.de> wrote:
> Hello out there,
> I want to build a servelt which access a database. To avoid
> race-conditions and to realize synchronous access, I decited to make a
> "Singe Thread" Servlet. But Eclipse told me that this is no longer a
> usable code.
>
> So what can I do else?
It's deprecated because it is confusing, but it is actually very
useful performance wise in some cases, since it does pooling. I will
make sure this feature remains available in the future.
--
xxxxxxxxxxxxxxxxxxxxxxxxx
Rémy Maucherat
Developer & Consultant
JBoss Group (Europe) SàRL
xxxxxxxxxxxxxxxxxxxxxxxxx
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org