Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread in JEE

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Query

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
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply,please address this point

5 objects(service layer+persistence layer) are multithreaded
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic