想象一个更复杂的CRUD应用程序,它具有三层架构并通过Web服务进行通信.客户端开始与服务器的对话,并做一些像向导一样的向导.要处理向导,客户端需要服务器提供的反馈.
我们开始讨论这种方法的有状态或无状态Web服务.我结合自己的经验做了一些研究,这让我想到了后面提到的问题.
具有以下属性的无状态Web服务(在我们的示例中):
+ high scalability
+ high availability
+ high speed
+ rapid testing
- bloated contract
- implementing more logic on server-side
Run Code Online (Sandbox Code Playgroud)
但是我们可以划掉前两点,我们的应用程序不需要高可伸缩性和可用性.
所以我们来到有状态的网络服务.我已经阅读了大量的博客和论坛帖子,实现有状态网络服务的最发明点是:
+ simplifies contract (protocol)
- bad testing
- runs counter to the basic architecture of http
Run Code Online (Sandbox Code Playgroud)
但几乎所有的Web应用程序都没有这些坏点吗?Web应用程序使用cookie,查询字符串,会话ID和所有内容来避免http的无状态.
那么为什么网络服务不好呢?
如果我想使用我的Web应用程序跟踪每个客户端的会话状态,这是一个更好的选择 - 会话Bean还是HTTP会话 - 要使用?
//request is a variable of the class javax.servlet.http.HttpServletRequest
//UserState is a POJO
HttpSession session = request.getSession(true);
UserState state = (UserState)(session.getAttribute("UserState"));
if (state == null) { //create default value .. }
String uid = state.getUID();
//now do things with the user id
Run Code Online (Sandbox Code Playgroud)
在ServletContextListener的实现中注册为Web应用程序监听器WEB-INF/web.xml:
//UserState NOT a POJO this this time, it is
//the interface of the UserStateBean Stateful Session EJB
@EJB
private UserState userStateBean;
public void contextInitialized(ServletContextEvent sce) {
ServletContext servletContext …Run Code Online (Sandbox Code Playgroud) 我已经在7批样品的多批次上训练了一个LSTM模型(用Keras和TF构建),每个样品有3个特征,下面的样本形状类似(下面的数字只是占位符以便解释),每个批次标记为0或1:
数据:
[
[[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
[[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
[[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
...
]
Run Code Online (Sandbox Code Playgroud)
即:m个序列的批次,每个长度为7,其元素是三维向量(因此批次具有形状(m*7*3))
目标:
[
[1]
[0]
[1]
...
]
Run Code Online (Sandbox Code Playgroud)
在我的生产环境中,数据是具有3个特征([1,2,3],[1,2,3]...)的样本流.我希望在每个样本到达我的模型时流式传输并获得中间概率而不等待整个批次(7) - 请参阅下面的动画.
我的一个想法是用缺少的样本填充批处理0,
[[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[1,2,3]]但这似乎是低效的.
我将非常感谢任何帮助,这些帮助将指引我以持久的方式保存LSTM中间状态,同时等待下一个样本并预测使用部分数据训练特定批量大小的模型.
更新,包括型号代码:
opt = optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=10e-8, decay=0.001)
model = Sequential()
num_features = data.shape[2]
num_samples = data.shape[1]
first_lstm = LSTM(32, batch_input_shape=(None, num_samples, num_features), return_sequences=True, activation='tanh')
model.add(
first_lstm)
model.add(LeakyReLU())
model.add(Dropout(0.2))
model.add(LSTM(16, return_sequences=True, activation='tanh'))
model.add(Dropout(0.2))
model.add(LeakyReLU())
model.add(Flatten())
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer=opt,
metrics=['accuracy', keras_metrics.precision(), keras_metrics.recall(), f1])
Run Code Online (Sandbox Code Playgroud)
型号摘要:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm_1 (LSTM) …Run Code Online (Sandbox Code Playgroud) 在 Flutter 中,StatefulWidget 具有dispose()和deactivate()。它们有何不同?
我想知道,以下两者之间的主要区别是什么:
我知道@SessionScoped和@Stateful允许为每个客户端创建一个新实例.我也知道,对于@ApplicationScoped和@Singleton/@Stateless,它们在客户端之间共享.
但是,我什么时候应该考虑选择一个EJB或另一个更好?
在1.7版本的Clojure Core文档中 - 以下功能
dedupe
disj!
dissoc!
filter
keep
map
random-sample
remove
replace
take-while
Run Code Online (Sandbox Code Playgroud)
在其API描述中包含以下文本
Returns a transducer when no collection is provided.
Run Code Online (Sandbox Code Playgroud)
以及以下功能
drop
keep-indexed
partition-all
partition-by
take
take-nth
Run Code Online (Sandbox Code Playgroud)
有以下文字.
Returns a *stateful* transducer when no collection is provided.
Run Code Online (Sandbox Code Playgroud)
此外 - 对这一措辞提出了批评.

我的问题是:什么是有状态传感器?即分组函数的相似之处.(这是说,之所以有人说键入一个传感器就需要依赖类型?)
我一直试图理解和展示Java流如何在引擎盖下实现一种循环融合,以便将几个操作融合到一个通道中.
这是第一个例子:
Stream.of("The", "cat", "sat", "on", "the", "mat")
.filter(w -> {
System.out.println("Filtering: " + w);
return w.length() == 3;
})
.map(w -> {
System.out.println("Mapping: " + w);
return w.toUpperCase();
})
.forEach(w -> System.out.println("Printing: " + w));
Run Code Online (Sandbox Code Playgroud)
具有以下输出(每个元素的单个传递的融合非常清晰):
Filtering: The
Mapping: The
Printing: THE
Filtering: cat
Mapping: cat
Printing: CAT
Filtering: sat
Mapping: sat
Printing: SAT
Filtering: on
Filtering: the
Mapping: the
Printing: THE
Filtering: mat
Mapping: mat
Printing: MAT
Run Code Online (Sandbox Code Playgroud)
第二个例子是相同的,但我使用filter和map之间的sorted()操作:
Stream.of("The", "cat", "sat", "on", "the", "mat")
.filter(w -> {
System.out.println("Filtering: …Run Code Online (Sandbox Code Playgroud) 我有一个简单的WCF服务,允许客户端/消费者应用程序通过提供用户名和密码登录.如果用户名和密码都正确,则WCF服务为客户端提供GUID.然后将GUID和用户名存储为WCF服务中的键/值对.从此处开始,客户端将每个请求的GUID作为识别手段发送.
由于我将键/值对存储在Dictionary/Hashmap中,因此只有在WCF服务有状态时,此方法才有效.问题是,它们是默认的有状态还是我必须做些什么来使它们以这种方式表现?
我尝试创建一个自定义有状态小部件。但我找不到任何有关如何在构造函数上设置默认值的参考。
举个例子:
class CustomWidget extends StatefulWidget {
final String buttonText;
final Function onPressed;
CustomWidget({Key key, @required this.onPressed, this.buttonText}) : super(key: key);
@override
_CustomWidgetState createState() => _CustomWidgetState();
}
class _CustomWidgetState extends State<CustomWidget> {
@override
Widget build(BuildContext context) {
return FlatButton(
onPressed: widget.onPressed,
child: Text(widget.buttonText),
);
}
}
Run Code Online (Sandbox Code Playgroud)
当我将小部件创建为另一个小部件的子级并包含所有属性时,它可以完美地工作
child: CustomWidget(
buttonText: 'Text of the button',
onPressed: () {},
)
Run Code Online (Sandbox Code Playgroud)
但是,当我将按钮文本排除在外时,应用程序崩溃了。
child: CustomWidget(
onPressed: () {},
)
Run Code Online (Sandbox Code Playgroud)
一个基本的解决方法是简单地添加行buttonText: ''. 我并不总是想在创建自定义小部件时专门处理每个自定义小部件的属性。
So my question is, how do I set default properties …
我们目前有一个注入Servlet的有状态bean.问题是有时候我们会Caused by: javax.ejb.ConcurrentAccessException: SessionBean is executing another request. [session-key: 7d90c02200a81f-752fe1cd-1]在有状态bean上执行一个方法.
public class NewServlet extends HttpServlet {
@EJB
private ReportLocal reportBean;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String[] parameters = fetchParameters(request);
out.write(reportBean.constructReport(parameters));
} finally {
out.close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,constructReport将检查是否需要打开与Report中指定的数据库的新连接,之后在根据指定的参数构建的查询中构建HTML中的Report.
我们选择在无状态bean上使用有状态bean的原因是因为我们需要打开与未知数据库的数据库连接并对其执行查询.对于无状态bean,使用每个注入的bean实例重复打开和关闭数据库连接似乎非常低效.