This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SingleThreadModel Deprecated  RSS feed

 
marlajee Borstone
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As per servlet 2.4, the SingleThreadModel is now deprecated. THen, how to make a Servlet thread-safe.

Dhansumaal
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Concurrency and thread-safety are big subjects that can't be dealt with appropriately in a forum post. I suggest you start reading the Sun Java Tutorial on that subject.

Fundamentally, you need to guard access to shared, mutable state (and I realize that you may not understand what that means before you dig deeper into the subject).
Shared means anything that can be accessed from more than a single thread - in a web app, that would by servlet instance variables, session contents, context parameters, amongst other things.
Mutable means that the value can change. It's no problem to have shared data if its value never changes (maybe initialization parameters). But anything that can have its value/data changed is a problem.

Any read or write access to shared, mutable state -which also includes databases and files- needs to be protected through one of the various means described in the tutorial, e.g. synchronization.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to code for it. For example, do dot declare variables that are shared accross requests, such as instance variables.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!