Home  >  Q&A  >  body text

线程 - java 进程通信问题

现在有这样一个场景。

有一个jar在多线程运行,每个线程里都有自己的局部变量累加器 long count;

现在我需要通过一个spring的web project获取每个线程的count值,并且通过highcharts绘制出图形

请问这个独立jar的各自线程中的count局部变量,如何能被spring拿到?

自己想到的几个方法:

1.NIO的管道通信,PipedInputStream、PipedOutputStream

2.Thrift RPC服务

3.netty的服务

有没有可行的解决方案?

伊谢尔伦伊谢尔伦2716 days ago353

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-18 10:35:14

    According to my understanding, you need inter-process communication, right?
    Thrift and Netty you mentioned are both acceptable.
    Or you can also use a message queue. Each jar package acts as a producer and submits count as a message to the queue, and then Your Spring Web project can retrieve the count value from the queue.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:35:14

    No need.
    Get data directly from count使用map结构存放在redis中就ok了。hightcharts渲染时直接从redis.
    The structure is as follows.

    counter
        |
        | key1: v1`
        | key2: v2

    reply
    0
  • Cancelreply