小编Cha*_*ens的帖子

调用@Stateless bean的@Asynchronous方法时的ContextNotActiveException

我@Stateless在异步Servlet中注入一个bean并@Asynchronous从Serrvlet 调用方法.在jboss的服务器日志中,我无法看到任何异常但是在启动Java Mission Control时,我会看到ContextNotActiveExcetionServlet调用该@Asyncrhonous方法的时候.

Servlet ::

@WebServlet(urlPatterns = { "/asyncservice" }, asyncSupported = true)
public class AsyncServiceServlet extends HttpServlet {

@Inject
private Service service;

protected void doPost(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    final AsyncContext asyncContext = request.startAsync(request, response);
    asyncContext.start(new Runnable() {
        @Override
        public void run() {
            try {
                service.service(asyncContext);
            } catch (ContextNotActiveException | IOException e) {
                e.printStackTrace();
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

服务类::

@Stateless
public class Service {

@Asynchronous
public …
Run Code Online (Sandbox Code Playgroud)

java asynchronous ejb stateless-session-bean java-ee

13
推荐指数
1
解决办法
1005
查看次数

在Ruby中将Float转换为String

有时当我尝试在rails中打印Float时,我收到如下错误:

TypeError at /delivery_requests/33/edit
no implicit conversion of Float into String

on the line: 
= this_is_a_float
Run Code Online (Sandbox Code Playgroud)

我知道我可以添加.to_s到浮点数,但为什么这不是默认情况下完成的?

ruby ruby-on-rails

5
推荐指数
1
解决办法
1万
查看次数

使用零将boost :: lexical_cast int转换为字符串填充

我需要创建生成名称的文件.我boost::lexical_cast用来将整数转换为std::string.是否有可能获得带填充零的字符串; 我没有c++11 tools,只有MSVS 2008支持的一切.

示例:

int i = 10;
std::string str = boost::lexical_cast<std::string>(i);

// str = "10"
// expect str = "000010"
Run Code Online (Sandbox Code Playgroud)

ps不建议使用sprintf.

c++ string boost lexical-cast

1
推荐指数
1
解决办法
1858
查看次数