Is there a way to make the handling threads in Jax-rs / Jersey communicate between them? If so, what would be the best way?
有没有办法让Jax-rs / Jersey中的处理线程在它们之间进行通信?如果是这样,最好的方法是什么?
1 个解决方案
#1
0
I think this is a bad design.
Each request-response should be autonomous as possible.
If you need inter-thread communications,
You can use standard j2se stuff,
For example, some synchronized data structure , and you can select one from the java.util.concurrent package.
You can have for example a singleton that can be accessed via its static getInstance method from all the threads, and have Thread A mark there that it executed
and is about to send some response to the client, and query via thread B if this thread was executed.
If you want thread B to wait until thread A, you can use some locking object, maybe Condition, , as suggested by @Wyzard
我认为这是一个糟糕的设计。每个请求 - 响应应尽可能自治。如果需要线程间通信,可以使用标准的j2se内容,例如,某些同步数据结构,您可以从java.util.concurrent包中选择一个。例如,你可以通过其所有线程中的静态getInstance方法访问一个单例,并在那里执行线程A标记,它将向客户端发送一些响应,如果此线程是,则通过线程B进行查询执行。如果你想让线程B等到线程A,你可以使用一些锁定对象,也许是条件,如@Wyzard所建议的那样
#1
0
I think this is a bad design.
Each request-response should be autonomous as possible.
If you need inter-thread communications,
You can use standard j2se stuff,
For example, some synchronized data structure , and you can select one from the java.util.concurrent package.
You can have for example a singleton that can be accessed via its static getInstance method from all the threads, and have Thread A mark there that it executed
and is about to send some response to the client, and query via thread B if this thread was executed.
If you want thread B to wait until thread A, you can use some locking object, maybe Condition, , as suggested by @Wyzard
我认为这是一个糟糕的设计。每个请求 - 响应应尽可能自治。如果需要线程间通信,可以使用标准的j2se内容,例如,某些同步数据结构,您可以从java.util.concurrent包中选择一个。例如,你可以通过其所有线程中的静态getInstance方法访问一个单例,并在那里执行线程A标记,它将向客户端发送一些响应,如果此线程是,则通过线程B进行查询执行。如果你想让线程B等到线程A,你可以使用一些锁定对象,也许是条件,如@Wyzard所建议的那样