小编Max*_*hka的帖子

ExecutorService中的awaitTermination"发生在之前执行的任何代码之前"吗?

请帮助理解ExecutorService#awaitTermination(timeout)行为.

我在我的代码中观察情况:

private void shutdownAndAwaitTermination(ExecutorService threadPool){
    threadPool.shutdown(); 
    try {
        if (!threadPool.awaitTermination(threadPoolTimeout, TimeUnit.HOURS)){
            threadPool.shutdownNow(); 
            if (!threadPool.awaitTermination(60, TimeUnit.SECONDS)) {
                logger.warn("Pool did not terminate");
            }
        }
    }
    catch (InterruptedException ie)     {
        threadPool.shutdownNow();
        Thread.currentThread().interrupt();
    }
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,池中的任务是否在同一线程中的shutdownAndAwaitTermination()之后的任何其他调用之前完成?

看看生产中发生了什么,我认为答案是否定的,但我只想了解如何确保在调用shutdownAndAwaitTermination()之后放置的任何代码都将在池中的最后一个任务完成后发生.

谢谢.

java concurrency threadpool threadpoolexecutor

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

如何实现基于Apache Thrift的golang服务异常?

我有一个用于方法的服务节俭接口,result如下所示:

exception SomeException {
    1: string message;
}

string result(
    1: string token,
    2: string identifier
) throws (
    1: SomeException ex,
);
Run Code Online (Sandbox Code Playgroud)

我如何在golang 中正确实现它?我希望为这个 Thrift 服务的客户正确抛出异常。

exception-handling exception thrift go

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

Gstreamer 接收视频:流任务暂停,原因未协商 (-4)

我正在尝试通过UDP协议通过网络传输RTP视频流。

这是发送方的管道代码:

https://gist.github.com/mgalushka/68d8ee034849a7db4f1f234e73a41405

如果我使用gst-launch-1.0如下命令行运行接收器,我可以接收并查看实际视频:

gst-launch-1.0 -v udpsrc address=127.0.0.1 port=1234 caps="application/x-rtp" ! rtph263pdepay ! avdec_h263 ! autovideosink
Run Code Online (Sandbox Code Playgroud)

但是当我在C代码中为同一管道执行接收器时,我看不到带有视频的窗口。这是接收器端的管道代码(完整的 - 因为我相信这里有错误):

void  _receive_video_init_gstreamer(NiceAgent *magent, guint stream_id, CustomData *data)
{
  GstElement *pipeline, *source, *capsfilter, *videoconvert, *h263p, *rtph263pdepay, *sink;
  GstBus *bus;
  GstMessage *msg;
  GstStateChangeReturn ret;
  GSource *bus_source;

  source = gst_element_factory_make ("udpsrc", "source");
  rtph263pdepay = gst_element_factory_make ("rtph263pdepay", "rtph263pdepay");
  h263p = gst_element_factory_make ("avdec_h263p", "h263p");
  sink = gst_element_factory_make ("autovideosink", "sink");

  g_object_set (source, "address", "127.0.0.1", NULL);
  g_object_set (source, "port", 1234, NULL);

  g_object_set (source, "caps", …
Run Code Online (Sandbox Code Playgroud)

c rtp video-streaming gstreamer

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

C++舍入到FE_TONEAREST

任何人都可以,请解释为什么舍入0.5FE_TONEAREST所赐0?它不应该给出"1"的结果吗?有没有办法来解决这个问题?

#include <fenv.h>
#include <iostream>
#include <cmath>

int main() {
    fesetround(FE_TONEAREST);
    std::cout << "Rounding 0.5 to nearest = " << std::rint(0.5) << std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

coliru上的runnable代码:http://coliru.stacked-crooked.com/a/9c179ca56f251628

c++ rounding-error rounding c++11

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

定义静态const std :: string类变量

如何定义静态const std :: string类变量,它可以安全地在我的程序中的任何地方使用?

第一种方法 - 失败静态初始化顺序fiasco:

文件:Consts.h

namespace constants {
    struct Consts {
        static const std::string kVar = "123";
    }
}
Run Code Online (Sandbox Code Playgroud)

第二种方法 - 导致复制kVar到我们包含此标题的每个翻译单元,这导致一个定义规则违规原则并且可能导致双重释放或在释放错误后使用 - 如果此定义包含在多个cpp文件中,则这是未定义的行为(我想做的,因为我想要全局共享std :: string const).

文件:Consts.h

namespace constants {
   const std::string kVar = "123";
}
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法(除了使用宏 - 这也是全局如此丑陋的解决方案)以安全的方式定义这样的var?这种结构的最佳实践经验是什么?

c++ const c++11

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