Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / January 2004

Tip: Looking for answers? Try searching our database.

Servlet Threads Database Connections

Thread view: 
killerTomato - 24 Dec 2003 20:24 GMT
I have been reading a lot of posts and websites about not creating
your own threads in a servlet and that you should not do it because it
is bad practice and will be illegal in the future.   What I don't
understand is why and what the alternatives are.  All I every see is
don't to it and no options are given.  It would seem like there are a
lot of reasons to do it.

Here is my scenario.  I have multiple databases that I would like to
query data from.  Each one is from some a different database server
and the queries are read only (just selects).  There is no data that
is being updated and even if there were updates I would not care about
if the data returned was a little stale.  I have one connection from
OS390, one AIX and one UDB NT.  I don't need to use any transactions
or state.  I just want the results.

Currently, my process queries each of them in sequence and then
displays the results.  I was going to try and create threads for each
call and see if that would make any performance differences, but after
reading all the posts it does not look like I should even attempt it.
It would seem like kicking off to 3 different database servers and
letting them run would be faster then the my current way.  Also, the
application server I am using is Websphere 5.

Thanks in advance for any links or info on my question.
Ben
Silvio Bierman - 26 Dec 2003 00:09 GMT
> I have been reading a lot of posts and websites about not creating
> your own threads in a servlet and that you should not do it because it
[quoted text clipped - 21 lines]
> Thanks in advance for any links or info on my question.
> Ben

Hello Ben,

There is nothing inherently wrong in creating threads in servlets. In fact,
very elegant and clean dedicated application servers can be created using a
servlet container for handling requests (HTTP/HTTPS) and using spawned
threads for running the server processes.

If we where talking about an EJB container that would be another thing. The
EJB container needs to be in control of threads and object lifetimes to
implement scalabitity features.

Since WS is both a servlet container and an EJB container this may have
caused the mixup.

Regards,

Silvio Bierman
killerTomato - 29 Dec 2003 12:59 GMT
Here is one of the sites that I had read.  

http://www-1.ibm.com/support/docview.wss?rs=180&context=SSEQTP&q=J2CA0075W&uid=s
wg21109248&loc=en_US&cs=utf-8&lang=en+en


It does mention EJBs, but the part after that was the part I was
concerned about.
"If a Servlet is spinning its own threads and accessing a database,
the J2EE specification is not clear on this, so WebSphere Application
Server 5.0 will allow it at this time. IBM is working with Sun to
clarify this in the specification, so eventually (i.e. J2EE 1.4) spun
threads from a Servlet accessing a database outside of a transaction
will not be supported either."

Any comments on that?

> > I have been reading a lot of posts and websites about not creating
> > your own threads in a servlet and that you should not do it because it
[quoted text clipped - 39 lines]
>
> Silvio Bierman
Nathan Zumwalt - 30 Dec 2003 18:52 GMT
Most of the time, a better and safer means of assynchronous execution
is available (such as JMS).  Unfortunatly, it seems your case is one
of those few that really needs threading.  I would still avoid using
your own threads, though... if you're getting data from such disparate
sources, your users should expect some performance degredation.  If
all this data is frequently accessed, then you really need a data
mart.

It would be nice if the JSP spec had some kind of assynchronous
include for cases like this one.  Something like:

...
<jsp:include page="page1.jsp" assync="true"/>
<jsp:include page="page2.jsp" assync="true"/>
<jsp:include page="page3.jsp" assync="true"/>
...

This assumes that concurrent access to shared resources (such as the
session) is  allowed.  I wouldn't think this would be something too
difficult for a servlet container to implement.

-Nathan

> Here is one of the sites that I had read.  
>
[quoted text clipped - 54 lines]
> >
> > Silvio Bierman
Scorpio - 04 Jan 2004 10:59 GMT
> Here is one of the sites that I had read.

http://www-1.ibm.com/support/docview.wss?rs=180&context=SSEQTP&q=J2CA0075W&u
id=swg21109248&loc=en_US&cs=utf-8&lang=en+en

> It does mention EJBs, but the part after that was the part I was
> concerned about.
[quoted text clipped - 6 lines]
>
> Any comments on that?

Hi,

I encountered the same problem a couple of weeks ago... My problem was, I
needed periodically start task (checking mail and execute some queries on
database) and I thought to use "independent" threads...
I found out the same IBM document you have reported in your post.
Well, the solution to this  problem is EJB 2.1 specification, which provides
a new EJB type ( Timer EJB) which will allow programmer to execute periodic
task.
I use WebSphere 5 too, but I do not know which version would support EJB 2.1
specs.
To solve my problem, I've started an external thread which periodically
executes SOAP calls to business logic classes on application server.

Regards,
 Scorpio.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.