Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronization in case of ServletContext attributes

 
krishna na
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I created a small Servlet where I enterd the synchronized block by obtaining the lock on ServletContext. Now current thread will sleep for 5 seconds & then set some attributes on ServletContext.

I found strange result. When I hit the servlet url from 2 browser windows., even though thread 1 had acquired the lock & was sleeping...thread2 also came inside synchronized block.

Thread 2 was not supposed to enter synchronized block right ?
 
Ankit Garg
Sheriff
Posts: 9578
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi krishna, welcome to javaranch.

Can you post your source code so that we can see what is wrong...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic