• 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: 9597
36
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...
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!