如何使 Java Web 应用程序完全无状态 [英] How to make a java web application fully stateless

查看:25
本文介绍了如何使 Java Web 应用程序完全无状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于有状态应用程序和无状态应用程序之间的区别的讨论,无状态就是函数编程语言所做的,每个具有相同参数的函数调用都会返回相同的值.

I know that there are many discussions on difference between stateful app and stateless app, and that stateless is what function programming language does, every function call with the same args will return the same value.

这是否意味着面向对象语言无法创建完全无状态的应用程序,因为每个对象通常都有状态.

Does it mean object-oriented language is not able to make a fully stateless application,since every object will typically have state.

另外,在Java web应用中,我们通常需要跟踪用户状态,这可以通过会话来解决.但是如何在分布式系统中以无状态方式做到这一点?

Also, in Java web application, we typically need to trace user state,and which is solved by session. But how to do that in distributed system with in stateless way?

当一个系统死机时,我们需要另一个服务器以某种方式识别会话,以便转移用户状态.我们是否需要将会话放在中央数据库(缓存)中?但这种方式是无状态的吗?

When one system dies, and we need the session can be recognized in some way by another server so that the user state will be transferred. Do we need to put the session in the central database(cache)?But is this way stateless?

在我们使 Java Web 应用程序无状态之前,除了会话之外,还有哪些事情需要关注?

What will be some things need to be concerned except session) to before we make a java web application stateless?

推荐答案

您不会在服务器上存储任何客户端状态信息,而是将其传递到需要它的任何地方,然后传递它当服务器需要更改某些内容时返回给客户端.这就是 stateless 的意思,没有状态.服务器不应该知道客户端处于什么状态,直到客户端告诉它状态是什么.

You don't store any client state information on the server, you pass it around to everywhere that needs it and you pass it back to the client when the server needs something changed. That is what stateless means, no state. The server should not have any clue about what state the client is in until the client tells it what the state is.

这篇关于如何使 Java Web 应用程序完全无状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆