我们目前有一个注入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实例重复打开和关闭数据库连接似乎非常低效.
我今天遇到了以下特有的行为.
以下代码适用于Python 3.3:
smtp = smtplib.SMTP()
smtp.connect(host="smtp.gmail.com", port=587)
smtp.ehlo()
smtp.starttls()
Run Code Online (Sandbox Code Playgroud)
在Pyhton 3.4中,上面的代码不起作用,而是遇到以下错误:
File "smtp_test.py", line 10, in <module>
smtp.starttls()
File "/usr/lib/python3.4/smtplib.py", line 676, in starttls
server_hostname=server_hostname)
File "/usr/lib/python3.4/ssl.py", line 344, in wrap_socket
_context=self)
File "/usr/lib/python3.4/ssl.py", line 540, in __init__
self.do_handshake()
File "/usr/lib/python3.4/ssl.py", line 767, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: TLSV1_ALERT_DECODE_ERROR] tlsv1 alert decode error (_ssl.c:598)
Run Code Online (Sandbox Code Playgroud)
如果上面的代码被修改为在构造函数中指定主机和端口而不使用connect方法,如下面的代码所示,那么它可以工作.
smtp = smtplib.SMTP(host="smtp.gmail.com", port=587)
smtp.ehlo()
smtp.starttls()
Run Code Online (Sandbox Code Playgroud)
OpenSSL版本1.0.1f和OpenSSL 1.0.1g发生上述行为
有人可以向我解释这种行为吗?
注意:我没有使用 Jooq 的代码生成器
在 DAO 单元测试中,DAO 被测试以确保在插入对象后,DAO 将 Id 设置为由数据库中的 last_insert_id() 返回。由于我使用的是 JOOQ 的 MockConnection 和 MockDataProvider,因此没有联系实际的数据库。
当 DAO 执行以下操作时:
DSLContext ctx = DSL.using(connection, SQLDialect.MYSQL);
//insert
//get id
BigInteger id = ctx.lastId();
Run Code Online (Sandbox Code Playgroud)
JOOQ 执行以下查询:
select last_insert_id() from dual;
Run Code Online (Sandbox Code Playgroud)
在我的 MockDataProvider 中,我检查何时执行此查询并相应地返回结果:
import static org.jooq.impl.DSL.dual;
//other code
@Override
public MockResult[] execute(MockExecuteContext ctx) throws SQLException {
Field<BigInteger> id = DSL.field("", BigInteger.class);
Record record = dual().newRecord();
record.setValue(id, BigInteger.valueOf(1234567));
return new MockResult[] { new MockResult(record) };
}
Run Code Online (Sandbox Code Playgroud)
当返回上述 MockResult 时,我得到以下异常
java.lang.IllegalArgumentException: Field () is …Run Code Online (Sandbox Code Playgroud)