Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is other method also synchronized

 
Sunil K Bansal
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic