小编Kár*_*eue的帖子

并行调用 List 的方法?

我必须遍历一个列表并为每个对象调用一个方法,但要并行执行。在循环之后,还有其他语句,它们必须等待并行方法调用。我怎么能在JAVA中做到这一点?

public void a(List<Object> list) {
    for(Object o : list) {
        asynchMethod(o); // this n method call must run in the same time
    }

    // wait for all asynchMethod result
    /**
     * ...other statements
     */
}

private void asynchMethod(Object o) {
    // some code
}
Run Code Online (Sandbox Code Playgroud)

java parallel-processing asynchronous async-await

3
推荐指数
1
解决办法
1530
查看次数

Hibernate找不到H2驱动程序

首先对不起我的英语

我有一个Hibernate和JPA的Maven项目。我已经注释了这些贵族。当我尝试运行程序时,显示此错误:

Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [org.h2.Driver]
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.h2.Driver
Run Code Online (Sandbox Code Playgroud)

这是我的hibernate.cfg.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

    <hibernate-configuration>
        <session-factory>
            <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
            <property name="hibernate.connection.driver_class">org.h2.Driver</property>
            <property name="hibernate.connection.url">jdbc:h2:mem:test</property>
            <property name="hibernate.connection.username">sa</property>
            <property name="hibernate.connection.password"></property>
            <property name="hibernate.hbm2ddl.auto">create-drop</property>
            <property name="show_sql">false</property>

            <mapping class="model.User"/>
        </session-factory>
    </hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)

这是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>agilexpert</groupId>
    <artifactId>agilexpert</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>      

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.195</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.3.6.Final</version>
        </dependency>

    </dependencies>

</project> …
Run Code Online (Sandbox Code Playgroud)

java hibernate h2 maven

1
推荐指数
1
解决办法
1059
查看次数