We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
这很简单。 这个想法是,你有一个执行器对象,它是一个 bean,它被传递到任何想要触发新任务的对象(在新线程中)。 好处是,您只需更改 Spring 配置即可修改要使用的任务执行器类型。 在下面的示例中,我将使用一些示例类 (ClassWithMethodToFire) 并将其包装在 Runnable 对象中来执行火灾; 您还可以在自己的类中实际实现 Runnable,然后在执行方法中调用
classWithMethodToFire.run()
。这是一个非常简单的例子。
这是 Spring beans:
It's pretty simple. The idea is that you have an executor object that's a bean, which is passed into whatever object wants to fire the new task (in a new thread). The nice thing is that you can modify what type of task executor to use just by changing the Spring config. In the example below I'm taking some example class (ClassWithMethodToFire) and wrapping it in a Runnable object to do the fire; you could also actually implement Runnable in a class of your own, and then in the execute method you'd just call
classWithMethodToFire.run()
.Here's a very simple example.
And here are the Spring beans: