我是Spring的异步任务执行新手,所以如果这听起来像个愚蠢的问题,请原谅我.
我读到@Async注释是从Spring 3.x开始在方法级别引入的,该方法的调用将异步发生.我还读到我们可以在spring配置文件中配置ThreadPoolTaskExecutor.
我无法理解的是,如何从tak执行器调用@Async注释方法让我们假设--AsyncTaskExecutor
早些时候我们曾经做过类似的事情:
@Autowired protected AsyncTaskExecutor executor;
Run Code Online (Sandbox Code Playgroud)
然后
executor.submit(<Some Runnable or Callable task>)
Run Code Online (Sandbox Code Playgroud)
我无法理解@Async注释方法和TaskExecutor之间的关系.
我尝试在互联网上搜索很多但却无法得到任何相关信息.
有人可以为此提供一个例子.
我正在尝试在我的Service类中实现并发方法调用.
我的服务类中有一些注释为@Async的方法,我试图同时调用所有这些方法.但这些方法是按顺序执行的.
这是我的服务类(虚拟):
@Service public class TestService {
public SomeDataType getSOmeDataType() {
try {
List<DataType> a = retrieveDataA().get();
List<DataType> b = retrieveDataB().get();
List<DataType> c = retrieveDataC().get();
List<DataType> d = retrieveDataD().get();
List<DataType> e = retrieveDataE().get();
}
catch (InterruptedException e) {
e.printStackTrace();
}
catch (ExecutionException e) {
e.printStackTrace();
}
return referralDetailsReferenceData;
}
@Async
private Future<List<DataType>> retrieveDataA() {
//method logic
}
@Async
private Future<List<DataType>> retrieveDataB() {
//method logic
}
@Async
private Future<List<DataType>> retrieveDataC() {
//method logic
}
@Async
private Future<List<DataType>> retrieveDataD() {
//method …Run Code Online (Sandbox Code Playgroud) 我有一个 JSP,我在其中通过 JSTL c:forEach 循环显示元素。这是一个嵌套循环,如下所示:
<c:forEach items="${auditBudgetData.auditBudgetTierOneList}" var="auditBudgetTierOne" varStatus="tierOneCount">
** Some Code **
<c:forEach items="${auditBudgetTierOne.auditBudgetTierTwoList}" var="auditBudgetTierTwo" varStatus="tierTwoCount">
** Some Code **
<c:forEach items="${auditBudgetTierTwo.auditBudgetItemList}" var="auditBudgetItem" varStatus="budgetItemCount">
<input type="hidden" name="tierOneIndex" value="${tierOneCount.count}">
<input type="hidden" name="tierTwoIndex" value="${tierTwoCount.count}">
<input type="hidden" name="budgetItemIndex" value="${budgetItemCount.count}">
**Element rows displayed here**
Run Code Online (Sandbox Code Playgroud)
现在,当用户选择最内层循环中的任何元素行时,我必须在 JS 中获取值。如您所见,我正在尝试获取每个嵌套循环的计数,如下所示:
<input type="hidden" name="tierOneIndex" value="${tierOneCount.count}">
<input type="hidden" name="tierTwoIndex" value="${tierTwoCount.count}">
<input type="hidden" name="budgetItemIndex" value="${budgetItemCount.count}">
Run Code Online (Sandbox Code Playgroud)
并尝试在 JS 中获取输入字段的值,如下所示:
var tierOneIndex = $('input[name="tierOneIndex"]').val();
var tierTwoIndex = $('input[name="tierTwoIndex"]').val();
var budgetItemIndex = $('input[name="budgetItemIndex"]').val();
Run Code Online (Sandbox Code Playgroud)
但无论我选择什么元素,我总是得到:
tierOneIndex = 0
tierTwoIndex = 0
budgetItemIndex = …Run Code Online (Sandbox Code Playgroud) JSP上有一个输入字段,用户可以在其中输入数字(负数和正数).我有一个JS函数来检查输入字段上的每个键上事件不是数字,它应该用空格替换它.
var txt = $(elem).val();
if(!(txt.match(/^-?[0-9]*$/))) {
$(elem).val(txt.replace(/^-?[0-9]+/g, ''));
}
Run Code Online (Sandbox Code Playgroud)
我的if条件工作正常,但我无法创建替换的正则表达式.
java ×3
spring-mvc ×3
asynchronous ×2
javascript ×2
spring ×2
concurrency ×1
jsp ×1
jstl ×1
regex ×1