aspose file tools
The moose likes Servlets and the fly likes is a service method thread safe or not Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "is a service method thread safe or not" Watch "is a service method thread safe or not" New topic
Author

is a service method thread safe or not

anarkali perera
Ranch Hand

Joined: Sep 10, 2009
Posts: 237
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

Joined: Jan 10, 2002
Posts: 56233
    
  13

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.

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56233
    
  13

Only if you do thread-safe things within it.
Keshav Prasad gurukul
Greenhorn

Joined: Feb 25, 2009
Posts: 14
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.

SCJP5 94% SCWCD5 86% SCBCD5 86%
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3670

Keshav Prasad gurukul wrote:You can implement SingleThreadModel interface ...

That's really Evil


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35258
    
    7
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.


Android appsImageJ pluginsJava web charts
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is a service method thread safe or not
 
Similar Threads
ActionServlet Thread Safe
Is my servlet threadsafe?
How Servlet works?
thread safe servlet
A question about thread safety and servlets