zoukankan      html  css  js  c++  java
  • Why javax.servlet Interface SingleThreadModel is deprecated? How to handle the concurrency in servlet?

    note : this is from jave doc.

    What is the SingleThreadModel for?

    Ensures that servlets handle only one request at a time. This interface has no methods.

    If a servlet implements this interface, you are guaranteed that no two threads will execute concurrently in the servlet's service method. The servlet container can make this guarantee by synchronizing access to a single instance of the servlet, or by maintaining a pool of servlet instances and dispatching each new request to a free servlet.

    Why deprecated?

    Note that SingleThreadModel does not solve all thread safety issues. For example, session attributes and static variables can still be accessed by multiple requests on multiple threads at the same time, even when SingleThreadModel servlets are used. It is recommended that a developer take other means to resolve those issues instead of implementing this interface, such as avoiding the usage of an instance variable or synchronizing the block of the code accessing those resources. This interface is deprecated in Servlet API version 2.4.

    What is the recommended way to handle concurrent in Servlet?

    The use of the SingleThreadModel interface guarantees that only one thread at a
    time will execute in a given servlet instance’s service method. It is important to
    note that this guarantee only applies to each servlet instance, since the container
    may choose to pool such objects. Objects that are accessible to more than one servlet
    instance at a time, such as instances of HttpSession, may be available at any
    particular time to multiple servlets, including those that implement
    SingleThreadModel.
    It is recommended that a developer take other means to resolve those issues instead
    of implementing this interface, such as avoiding the usage of an instance variable or
    synchronizing the block of the code accessing those resources. The
    SingleThreadModel Interface is deprecated in this version of the specification.

  • 相关阅读:
    WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
    Django安装与使用
    初识Django
    python学习之xlrd的使用
    python 学习笔记
    根据当前日期生成一个唯一标识的名称
    用Python生成组织机构代码,附源码
    IO流基础
    多线程
    日期时间类
  • 原文地址:https://www.cnblogs.com/malaikuangren/p/2839640.html
Copyright © 2011-2022 走看看