我知道我对这个春天的东西很陌生,但我一整天都被困在这个问题上。我不太喜欢提问,但也许我会得到一个想法。
所以这是我的问题:我正在尝试创建一个队列来处理后端的内容。我通过在组件类中创建一个静态 executorservice 并使用帮助方法来运行它们来做到这一点。它似乎像我想要的那样工作,当我在类中连接时,我可以进入这些类,但是当它们运行时,它们似乎丢失了应用程序上下文(或者这只是我的猜测)。
我确信有更好的方法可以做到这一点,但在我正在使用的自定义框架中,有许多功能对我不起作用。我没有 spring-config.xml,不能使用@Configuration
执行器服务组件
@Component
public class FifoComponent {
public static ExecutorService executors = Executors.newSingleThreadExecutor();
private static Lock lock = new ReentrantLock(true);
public static void executeNewTestJob(int i) {
lock.lock();
OrderAllocationTestJob job = new OrderAllocationTestJob(i);
executors.execute(job);
lock.unlock();
}
}
可运行组件 - 请注意 appdateutils 有一个方法可以调用一个组件,该组件在我的典型 tomcat 环境中运行良好
@Component
public class OrderAllocationTestJob implements Runnable {
int i;
public OrderAllocationTestJob(int i) {
this.i = i;
}
@Override
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Asynchronous task " + i);
System.out.println(AppDateUtils.getCurrentTimeStamp());
}
}
从 struts 2 操作(测试)调用我知道我可以从调用 appdateutils.gettime 方法
for (int i = 0; i < 50; i++) {
FifoComponent.executeNewTestJob(i);
}
这是我最终得到的例外情况“范围'请求'对于当前线程无效”
一只甜甜圈
吃鸡游戏
宝慕林4294392
相关分类