等待ExecutorService完成所有任务的最简单方法是什么?我的任务主要是计算,所以我只想运行大量的工作 - 每个核心一个.现在我的设置如下:
ExecutorService es = Executors.newFixedThreadPool(2);
for (DataTable singleTable : uniquePhrases) {
es.execute(new ComputeDTask(singleTable));
}
try{
es.wait();
}
catch (InterruptedException e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
ComputeDTask实现runnable.这似乎正确执行任务,但代码崩溃wait()了IllegalMonitorStateException.这很奇怪,因为我玩了一些玩具示例,它似乎工作.
uniquePhrases包含数万个元素.我应该使用其他方法吗?我正在寻找尽可能简单的东西
Spring的3.0版本现在是GA版本,之前他们已经推出了3.0 RC1,RC2版本,还有Spring 3.0 M2版本.GA,RC,M版本有什么区别?
我以前读了几篇Java 8教程.
现在我遇到了以下主题: java支持Currying吗?
在这里,我看到以下代码:
IntFunction<IntUnaryOperator> curriedAdd = a -> b -> a + b;
System.out.println(curriedAdd.apply(1).applyAsInt(12));
Run Code Online (Sandbox Code Playgroud)
我明白这个例子总结了2个元素,但我无法理解构造:
a -> b -> a + b;
Run Code Online (Sandbox Code Playgroud)
根据表达式的左侧部分,该行应实现以下功能:
R apply(int value);
Run Code Online (Sandbox Code Playgroud)
在此之前,我只用一支箭只遇到了lambdas.
你能帮我写一下这个代码的spring mvc风格模拟吗?
session.setAttribute("name","value");
Run Code Online (Sandbox Code Playgroud)
以及如何将一个注释@ModelAttribute注释的元素添加到会话中,然后获取对它的访问权限?
我目前正在以下列方式创建整数常量.
public class Constants {
public static int SIGN_CREATE=0;
public static int SIGN_CREATE=1;
public static int HOME_SCREEN=2;
public static int REGISTER_SCREEN=3;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试以枚举方式执行此操作时
public enum PAGE{SIGN_CREATE,SIGN_CREATE,HOME_SCREEN,REGISTER_SCREEN}
Run Code Online (Sandbox Code Playgroud)
当我用PAGE.SIGN_CREATE它时应该返回1;
我尝试使用hibernate验证器编写非常简单的应用程序:
我的步骤:
在pom.xml中添加以下依赖项:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.1.Final</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
写代码:
class Configuration {
Range(min=1,max=100)
int threadNumber;
//...
public static void main(String[] args) {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Configuration configuration = new Configuration();
configuration.threadNumber = 12;
//...
Set<ConstraintViolation<Configuration>> constraintViolations = validator.validate(configuration);
System.out.println(constraintViolations);
}
}
Run Code Online (Sandbox Code Playgroud)
我得到以下stacktrace:
Exception in thread "main" javax.validation.ValidationException: Unable to instantiate Configuration.
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:279)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)
...
at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:110)
at org.hibernate.validator.internal.engine.ConfigurationImpl.<init>(ConfigurationImpl.java:86)
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:41)
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:276)
... 2 more
Run Code Online (Sandbox Code Playgroud)
我错了什么?
我知道这些方法的执行顺序不同,但在我的所有测试中,我都无法实现不同的顺序执行.
例:
System.out.println("forEach Demo");
Stream.of("AAA","BBB","CCC").forEach(s->System.out.println("Output:"+s));
System.out.println("forEachOrdered Demo");
Stream.of("AAA","BBB","CCC").forEachOrdered(s->System.out.println("Output:"+s));
Run Code Online (Sandbox Code Playgroud)
输出:
forEach Demo
Output:AAA
Output:BBB
Output:CCC
forEachOrdered Demo
Output:AAA
Output:BBB
Output:CCC
Run Code Online (Sandbox Code Playgroud)
请提供两种方法产生不同输出的示例.
在IDEA中,我试图推动一些提交.
我要求在远程服务器上看起来像单个操作.
我点击按下并看到以下窗口

我希望在这里看到壁球复选框但是看不到它.
请帮我.
我使用spring 3.2 mock mvc来测试我的控制器.我的代码是
@Autowired
private Client client;
@RequestMapping(value = "/user", method = RequestMethod.GET)
public String initUserSearchForm(ModelMap modelMap) {
User user = new User();
modelMap.addAttribute("User", user);
return "user";
}
@RequestMapping(value = "/byName", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public
@ResponseBody
String getUserByName(@RequestParam("firstName") String firstName,
@RequestParam("lastName") String lastName, @ModelAttribute("userClientObject") UserClient userClient) {
return client.getUserByName(userClient, firstName, lastName);
}
Run Code Online (Sandbox Code Playgroud)
我写了以下测试:
@Test
public void testGetUserByName() throws Exception {
String firstName = "Jack";
String lastName = "s";
this.userClientObject = client.createClient();
mockMvc.perform(get("/byName")
.sessionAttr("userClientObject", this.userClientObject)
.param("firstName", firstName)
.param("lastName", lastName) …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
public class MyClass{
...
}
Run Code Online (Sandbox Code Playgroud)
在同一个工作区,我有以下课程
public class AnotherClass{
@Autowired
MyClass myClass;
...
}
Run Code Online (Sandbox Code Playgroud)
如果我单击鼠标右键MyClass(首先提到)并选择"打开调用层次结构",我什么都看不到.
如何在Eclipse中找到这种用法?
java ×6
java-8 ×2
spring ×2
spring-mvc ×2
commit ×1
constants ×1
currying ×1
eclipse ×1
enums ×1
foreach ×1
git ×1
hibernate ×1
java-stream ×1
lambda ×1
maven ×1
push ×1
servlets ×1
session ×1
threadpool ×1
validation ×1