英文:
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
操作很棒,但必须遵循“一次只能在一个线程上进行一次操作”的规则;
实际上只有两件事情要做。
- 向Eclipse请求一个扩展操作的功能。
- 可能可以使用操作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.
- Ask Eclipse for a feature that expands how Operations work
- 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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论