• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is a service method thread safe or not

 
anarkali perera
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in a servlet there is a service method.is it thread safe or not.
1) if it is not what hapeen when there are two request come to servlet?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on JSP. For more information, please read this.

This post has been moved to a more appropriate forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only if you do thread-safe things within it.
 
Keshav Prasad gurukul
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since only one Instance of Servlet is present for whole application,
We have take certain consideration while having thread safety.
Request Scoped attribute is thread safe.

You can implement SingleThreadModel interface but i recommend
you to use synchronized blocks.
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keshav Prasad gurukul wrote:You can implement SingleThreadModel interface ...

That's really Evil
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can implement SingleThreadModel interface but i recommend you to use synchronized blocks.

You're right that one absolutely should not use SingleThreadModel, but synchronization is only one tool of many in the Java language's arsenal for making things thread-safe. Others are volatile, ThreadLocal and the classes in the java.util.concurrent package hierarchy. I recommend to read up on Java concurrency to fully understand the issues and solutions; see the http://faq.javaranch.com/java/ThreadsAndSynchronizationFaq for links to the two excellent books available on the topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic