Results 1 to 6 of 6
  1. #1
    udayadas's Avatar
    udayadas is offline Member
    Join Date
    Aug 2008
    Posts
    22
    Rep Power
    0

    Post Synchronized Servlet

    Just for the sake of testing...i declared by doGet()/doPost() as synchronized.It works.

    But what could it actually mean.Does that make my servlet a single threaded servlet.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    It means you only get one connection at a time. Any additional connection would wait until the connections before it are finished.

  3. #3
    sagarbirari is offline Member
    Join Date
    Sep 2008
    Posts
    17
    Rep Power
    0

    Default

    Hello

    Yes . means at time only one thread can enter in doGet()/doPost() method.but this is not standard programming, Instead of used synchronized block on code,when you expect that more than 2 threads may operate on your code and they may inconsistent your data.


    Regards

  4. #4
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    It means you won't be able to handle any load. Your application will not scale.

    This is a crude solution that is not recommended.

  5. #5
    sagarbirari is offline Member
    Join Date
    Sep 2008
    Posts
    17
    Rep Power
    0

    Default

    If you want performance then used synchronized block

  6. #6
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    Quote Originally Posted by sagarbirari View Post
    If you want performance then used synchronized block
    This is way to general. And perhaps misleading. There is no difference between using a synchronized block and using synchronization on an object with the same scope as the block. The compiler just does the same thing as you would manually.

    If you want to get performance and scaling, you have to carefully decide what needs synchronization and what types of locking it needs. The key is to obtain the fewest locks and locks of the weakest strength practical, for the shortest time.

    Look at things like java.util.concurrent.locks.ReentrantReadWriteLock

Similar Threads

  1. servlet
    By kondalrao.p in forum Java Servlet
    Replies: 1
    Last Post: 09-06-2008, 01:10 PM
  2. synchronized
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-28-2007, 10:33 AM
  3. Replies: 1
    Last Post: 08-07-2007, 03:47 PM
  4. doubt about synchronized
    By simon in forum Advanced Java
    Replies: 2
    Last Post: 08-05-2007, 03:49 AM
  5. Return in the Middle of synchronized Block
    By ariak in forum Advanced Java
    Replies: 1
    Last Post: 07-26-2007, 10:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •