File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Thread in JEE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread in JEE" Watch "Thread in JEE" New topic

Thread in JEE

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 580
I developed a JEE application,in spring and hibernate .All my business logic are simple POJO.While I design I never worried about Mutlthreading.I deployed my application in Tomcat.

As per my understanding servlet are multithreaded so many request comes to access the same servlet then it will be mutithreaded.

In my application , to get a value from database 3 objects in service layer and 2 objects in persistence layer are involved


1)if many users want to access my application at a time for getting value from database ,then server(tomcat) create each thread for a user
that means all the 5 objects(service layer+persistence layer) are multithreaded and given to single user? so each thread contain 5 objects?
Vinod K Singh
Ranch Hand

Joined: Sep 30, 2008
Posts: 198
Server will create separate thread to serve all users only when they send the request simultaneously if there is time difference among request then it is possible that only couple of treads can serve 5 users.

About how many instances will be created, all that depends how you coded your application. For example if there is a singleton class then one instance will be shared by all threads.

My Blog
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 580
Thanks for your reply,please address this point

5 objects(service layer+persistence layer) are multithreaded
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Objects aren't multi-threaded - they are or are not threadsafe. Which one of those is the case depends on how you wrote them. And whether it's a problem if they're not depends on whether they're exposed to multiple threads. As Vinod said, we can't speak to that, because we don't know how your code creates and uses those objects.
I agree. Here's the link:
subject: Thread in JEE
jQuery in Action, 3rd edition