• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when a class implements singleThread model

 
krishna Gajarla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i am bit new to java/j2ee please do not mind if my questions are simple.



when a class implents a singleThread model then which variables are single threaded.
 
IM Mahesh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implementing SinglrThreadModel would mean only one thread at a time can create or use instance or methods of that class. As per my knowledge it is supposed to be used only in servlet programming.
Correct me if i am wrong.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are plenty of classes that are not thread safe. If two or more threads use the same instance at the same time they'll get bad results, probably because the two threads will get into "race" conditions on member variables. You'll find such warnings in the standard library JavaDoc now and then. It's up to you to make sure you don't use them in two threads.

As mentioned above, servlets are the only place I've heard "single thread model" as a term. Single thread servlets have been mostly abandoned as a bad idea. Instead by default a single instance of a servlet services many threads, and you have to write your servlets to be thread safe by making sure they use static and member variables correctly.
[ April 11, 2006: Message edited by: Stan James ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic