• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Looking for Base Idea behind Multithreading Concept

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

Please help me to think about multithreading basic concept.

Let say we have a web application which is deployed on an application server , now how the multi-threading will come into picture , how does that situation comes when we say same variable is getting used by two or multiple instances or requests . when we should start thinking about multithreading during our development time. I understand synchronization , wait , sleep , notify and all those things but not able to understand exactly when do i need it? whose job is this to handle multithreading .. Web Server or Code ..

In a very short sentences , if somebody can guide me before we say i have two threads .... or Thread A is writting while Thread A is reading or something like this.

Thanks in advance , looking for good discussion.


Thanks
 
Ranch Hand
Posts: 88
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ankit,(Regarding how web-server works)

Thread:Thread is nothing but small small prog executed on perticular system.

Lets take one small example..Say take Facebok .There are 'n' numbers of users of fb.Now when you open the browser and hit fb.com a defult thread is created which is my main thread.When you login to that system another thread is created which is registered under your user id and all the opreration regarding to your profile will keep track by your thread only.Smilarly there are billion number of thread created by web-server to to give concurrent users to use one site.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although I know RatiKanta pal is trying to be helpful here, I think I have to speak up and say that essentially all of this is factually wrong. Web servers don't create one thread per user, and Facebook.com is most certainly not running billions of threads in parallel.

Nor are all the requests for a given user handled by one thread; a small pool of threads handles requests as they come in, without concern for previous history. The number of threads in the pool is based on what the server hardware can handle, not on the number of users. State for a user is held in cookies in the web browser and and in session objects on the server; the session objects are examined by code running in a thread that handles a request.

Threads in a web server allow multiple requests to be handled at once. Multiple threads can be calling the service method of a single servlet object at the same time, and they won't interfere, as long as there is no data that must be shared between threads.

If your servlet objects have member variables whose values can change during execution, then you need to be concerned about writing multithreaded code. Most of the time, however, this isn't a concern, as you don't normally store data like that in your servlets. As I said, you store it in the session.
 
RatiKanta pal
Ranch Hand
Posts: 88
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Ernest Friedman-Hill,

Thank you for your information.

Previously i was assuming , session is one thread.and though that thread all operation carried out..Now i think its clear to me.

Rati.
 
reply
    Bookmark Topic Watch Topic
  • New Topic