File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes is other method also synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "is other method also synchronized" Watch "is other method also synchronized" New topic
Author

is other method also synchronized

Sunil K Bansal
Ranch Hand

Joined: Jan 04, 2001
Posts: 62
i m writing a servlet
as in servlets doGet() and doPost() methods are synchronized
if i m writing a method which is not synchronized
and i m calling that method from
doGet() or doPost()
is that method also becomes synchronized
eg. brief code below
class A extends HttpServlet
{
Connection con;
public void init(Serv......)
{
//code
}
public void doGet(Htt....)
{
//code
aMethod();
}
public void aMethod()
{
//code
}
}
Bansal
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Sunil K Bansal:
i m writing a servlet
as in servlets doGet() and doPost() methods are synchronized

But they are not, unless you implement SingleThreadModel. Don't make them synchronized as in prefixing them with "synchronized"!

if i m writing a method which is not synchronized
and i m calling that method from
doGet() or doPost()
is that method also becomes synchronized
eg. brief code below

If you're inside a synchronized method, your thread has a monitor lock on the servlet object. You will keep that monitor even when calling other method and lose it only upon leaving the synchronized method (or if you call wait()).
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is other method also synchronized
 
Similar Threads
HTML username password sending to servlet
Delegating to doGet()
Default action of <a href="link">
HTTP Status 405 - HTTP method GET is not supported by this URL
Can I call a servlet directly from HTML