Disable HTTPSession for stateless web services [du

2019-09-23 20:00发布

This question already has an answer here:

I would like to know if it is possible to disable the HTTPSession for an application server handling only web services RESTful.

I don't know if there are specific application servers or servlet containers designed to handle micro RESTful web services.

I think that disabling completely the session concept will give the following advantages:

  • Better performances
  • No risk to save data in the session breaking the concept of stateless of a RESTful webservice
  • Less classes loaded by the classloader
  • No unused information is saved in the session (for example the session id, session state)
  • less access to synchronized blocks (I think that at least in the Session the value of lastAccessedTime is updated for every request and this should be done in a synchronized block)

If there is no application server or servlet container that can do that: Is there any other Java engine that can handle micro services without creating something similar to an HttpSession?

2条回答
2楼-- · 2019-09-23 20:26

You can't completely disable the HttpSession.

But you can ensure a HttpSession won't be created in your application. To do it, ensure the following methods are not being invoked (by yourself or by the frameworks you are using):


Microservices is an architecture design principle. If you want to use Spring, there's a guide you can follow.

查看更多
小情绪 Triste *
3楼-- · 2019-09-23 20:27

You cannot disable HttpSession on a servlet container, like Tomcat.

Maybe Play framework would be a good approach for implementing your design.

查看更多
登录 后发表回答