HK2操作与线程ID无关

huangapple go评论71阅读模式
英文:

HK2 Operation independent from Thread Id

问题

我正在使用HK2 Operations 在一个包含REST服务器组件的Java SE应用程序中管理自定义范围。REST部分由Jersey提供。

Jersey允许资源返回(可能是缓慢或长时间运行的)StreamingOutput,而不是离散的实体。据我了解,这提供了一种在较低层处理的异步行为形式。我观察到的情况是,在流输出运行时,处理初始Jersey请求的线程再次空闲,以处理新的Jersey请求,这些请求需要它们自己的范围。

HK2表示:

> HK2操作提供了一组方便的工具,用于构建遵循“每次线程上的一个操作”的一般规则的范围/上下文对。

不幸的是,这就是冲突的地方。当传入的请求被路由到已经/仍在其他地方为StreamingOutput提供服务的同一线程时,无法启动操作:

java.lang.IllegalStateException: The operation OperationHandleImpl(OperationIdentifier(326193,my.TransactionScope),254339200) is active on 62

关于如何解决此问题,您有什么建议吗?

英文:

I'm using HK2 Operations to manage a custom scope in a Java SE application which contains a REST server component. The REST part is provided by Jersey.

Jersey allows a resource to return a (possibly slow or long-running) StreamingOutput instead of a discrete entity. As I understand, this provides a form of asynchronous behaviour handled a lower layers. What I observe is that while the streaming output is running, the thread that handled the initial Jersey request is free again to take on new Jersey requests, which require their own scope.

HK2 says:

> HK2 Operations provide a convenient set of tools for building scopes/context pairs that follow the general rule of “one operation on a thread at a time.”

Unfortunately, this is where it collides. When an incoming request is routed to the same thread that is already/still serving a StreamingOutput to somewhere else, the operation cannot be started :

java.lang.IllegalStateException: The operation OperationHandleImpl(OperationIdentifier(326193,my.TransactionScope),254339200) is active on 62

Any tips on what to do?

答案1

得分: 0

操作很棒,但必须遵循“一次只能在一个线程上进行一次操作”的规则;

实际上只有两件事情要做。

  1. 向Eclipse请求一个扩展操作的功能。
  2. 可能可以使用操作API本身来检测操作是否在运行... 如果是的话... 而是在一个不同的线程中分叉,然后在那里继续你的操作(这完全是一种技巧,但可能会起作用)。
英文:

Operations are gr8, but must follow the rule of "one-operation-on-a-thread-at-a-time"

There are really only two things to do.

  1. Ask Eclipse for a feature that expands how Operations work
  2. It may be possible to use the operation api itself to detect if an operation is running... and if it is... instead fork a different thread and continue your operation there (total hack but... probably would work).

huangapple
  • 本文由 发表于 2020年8月31日 16:50:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63667660.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定