• 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

Multithreading in the new Beta

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since the Single Threaded model has been deprectaed in the new version, what things should now about multithreading in servlet 2.4. (I couldnt get much of the new exam objective).
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Objective 3.2 is the only objective to talk about multi-threading. The exact wording is "... and identify multi-threading issues associated with each scope." Each scope meaning of course request, session and application.
Each scope allows one to use the set/getAttribute() method to store/retrieve objects. You will have to know in which circumstances access to objects in each of the scopes is thread-safe or not.
The context scope is not thread-safe as objects stored in it are accessible to any servlet in the web application. For instance, think about a list stored in the context scope. One servlet stores/removes elements in/from the list and another servlet just lists the content of the list. What would happen if the first servlet removes an element from the list while the second is enumerating it? Right, IndexOutOfBoundsException. Two solutions: either you synchronize access to the list (=> bottleneck) or you create a temporary copy of the list before enumerating it in the second servlet (=> costly in case of big lists).
The session scope may not be thread-safe either in the case the user opens multiple browser windows and performs several concurrent requests to the web application. Same example as before, the first servlet (accessed in one window) adds and removes elements from a list stored in the session scope. The second servlet (accessed in another window) just enumerates the elements of the list. If the user removes an element from the list in the first window and tries to enumerate the list in the second window at the same time, we also get the infamous IndexOutOfBoundsException. Again, two solutions: synchronize access to the list or synchronize the session object.
The request scope is always thread-safe because a new request object is created (or reused) upon each new client request. Therefore, there is no way two threads may be accessing the request object simultaneously unless you create multiple threads in the service method that access the request object.
Also, it might be good to know that local variables are always thread-safe because each thread executing a method will get a new copy of the local variable. Static variables are never thread-safe because they are shared by all instances of the class and instance variables might not always be thread-safe depending on the threading model (thread-safe only when implementing the SingleThreadModel interface which is now deprecated).
Briefly, I think this is what one should know for the purpose of the beta exam.
Happy learning
[ January 07, 2004: Message edited by: Valentin Crettaz ]
 
Mehdi Chaouachi
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really thank you Val for this info.
 
The moustache of a titan! The ad of a flea:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic