如何在Java EE环境中创建线程?(How to create threads in Java EE environment?)
我有一个要求,我必须在表中保留一些数据,持久可能需要一些时间。 基本上我想坚持一个日志。 我不希望执行等到持续完成。
我知道我必须使用线程来完成这项任务,并且我知道在企业应用程序中创建线程是不鼓励的。
于是我开始阅读有关工作经理的知识,并在websphere应用服务器8.5中了解并尝试了一个示例程序。
我从websphere使用asynchbeans.jar,现在我很困扰我正在编写供应商特定的代码。
然后我遇到了在Oracle java文档中描述的commonj work api。 现在我想使用fabric3的commonj api。
我怀疑的是,有没有更好的方法来完成同样的任务? 一种EJB方式? 或者工作经理对我的要求有好处?
I have a requirement where I have to persist some data in a table and the persisting may take sometime. Basically I want to persist a log. I don't want the execution to wait till the persisting finishes.
I know I have to use threads to accomplish this task and I know that it is discouraged to create threads in an enterprise application.
So I started reading about worker manager and understood and tried a sample program in websphere application server 8.5.
I used asynchbeans.jar from websphere and now I am bothered that I am writing vendor specific code.
Then I came across commonj work api which is described in oracle java documentation. Now I am thinking to use commonj api from fabric3.
My doubt is, is there a better way to accomplish the same task? An EJB way? Or work manager is good for my requirement?
原文:https://stackoverflow.com/questions/34788234
最满意答案
@PathVariable
标识传入请求的URI中使用的模式。Query args(
@RequestParam
)用于独占查询/搜索资源。 它们包含影响查询的数据。以下是创建良好网址的一些提示 。
@PathVariable
identifies the pattern that is used in the URI for the incoming request.Query args (
@RequestParam
) are used on querying/searching resources exclusively. They contain data that affects the query.Here are some tips for creating good URLs.
相关问答
更多-
@PathVariable和@ModelAttribute的值重叠(Values of @PathVariable and @ModelAttribute overlapping)[2023-08-20]
这种方法如何 - @RequestMapping(value = "/{id}", method = RequestMethod.GET) public String showItem(@PathVariable("id") Long id, Model uiModel) { User user = (User)uiModel.asMap().get("user"); ... } How about this approach - @RequestMap ... -
您应该能够通过定义与请求参数匹配的对象等来完成此操作。 示例(未经测试): public class MyRequest { @NotNull private String customerId; @NotNull private String reason; @NotNull @NotEmpty private List
attributes; // getters and setters left out for brevity. } ... -
创建您自己的自定义类,如下所示 Class Request { private String id; //getter and setter } 并改变方法 @RequestMapping(value = "/magic", method = RequestMethod.PUT) TodoDTO magic(@RequestBody Request request){ return service.magic(request.getId()); } 您也可以在URL中使用 ...
-
经过调试,我终于找到了什么问题。 它在我的代码中,而不是在Spring中。 在Welcome2Controller.groovy中写道: @RequestMapping(name = '/{name}', method = RequestMethod.GET) 它应该是 @RequestMapping(value = '/{name}', method = RequestMethod.GET) 感谢@cfrick的帮助:) After debugging, I finally find what's w ...
-
@PathVariable用于URL参数,如: /groups/{groupId}/google-places 。 如果参数是在? 你应该使用@RequestParam注解。 @RequestMapping(value = "/foo", method = RequestMethod.GET) public List
doNearbySearch(@RequestParam Float latitude) { LOGGER.trace("Searching fo ... -
更改: "/session/1?startSequence=4&?endSequence=6" 为了它: "/session/1?startSequence=4&endSequence=6" 这个? 仅在第一个参数中使用,之后您可以使用&添加更多参数。 Change it: "/session/1?startSequence=4&?endSequence=6" For it: "/session/1?startSequence=4&endSequence=6" The ? is used at on ...
-
如果要遵守“statefull”网址,请使用@PathVariable 。 例如:- /customer/:id Customer view/edit page /customer/ Customer Add page /customer/list List Customer Page /customer/:cid/order All order of a Customer /customer/:cid/order/:oid Specific order of a partucular ...
-
究竟什么是@RequestParam以及它是如何填充的?(What exactly is @RequestParam and how does it get populated?)[2022-02-06]
它也适用于帖子。 你可以发布你的方法体和你的HTML吗? It works with posts too. Can you post your method body and you html? -
什么时候选择@RequestParam而不是@PathVariable,反之亦然?(When to choose @RequestParam over @PathVariable and vice-versa?)[2022-08-01]
@PathVariable标识传入请求的URI中使用的模式。 Query args( @RequestParam )用于独占查询/搜索资源。 它们包含影响查询的数据。 以下是创建良好网址的一些提示 。 @PathVariable identifies the pattern that is used in the URI for the incoming request. Query args (@RequestParam) are used on querying/searching resources ... -
休息约定是使用uri变量: get http://stackoverflow.com/users/3630157 Rest convention is to use uri variables : get http://stackoverflow.com/users/3630157