我已经在两周前创建了一个程序(SPRING
+ HIBERNATE
)Maven
,现在它在加载JDBC驱动程序时遇到了问题(直到现在才发生).所以,我的pom.xml
文件看起来像这样:
<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>com.spring.hib</groupId>
<artifactId>HibPav</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.27</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-hibernate3</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.7.Final </version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
看来这个文件很清楚.但是在我尝试创建dataSource
bean 时,无法加载JDBC驱动程序的主要问题是什么.
其他文件:
数据源文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>properties/database.properties</value>
</property>
</bean>
<bean id="dataSource" …
Run Code Online (Sandbox Code Playgroud) 它是关于一个例子wait()
,并notify()
在Java并发.我对它的理论知识没有解释我这个代码,我无法解释为什么这会给我一个误解的结果.
所以,这是获得想法的代码:
public class ExampleOne {
public static void main(String[] args) {
Test b = new Test();
b.start();
synchronized(b){
try{
b.wait();
} catch(InterruptedException ex){
ex.printStackTrace();
}
System.out.println(b.total);
}
}
}
class Test extends Thread {
int total;
@Override
public void run(){
synchronized(this){
for(int i =0;i<50;i++){
total+=i;
System.out.println("I am here");
}
notify();
}
}
}
Run Code Online (Sandbox Code Playgroud)
结果是: 4950
那么,如何理解这个过程(怎么total
可能是4950)?
我明白,如果我调用wait()
它会停止调用此方法的对象的线程并唤醒它然后另一个线程调用notify()
.此外,synchronized()
块限制线程并且一次只接受一个线程.
所以当线程调用notify()时,它会变为非活动状态,直到其他线程调用wait()?
wait()和notify()如何在此代码中扮演角色?还synchronized()
阻止?
那么,在这段代码中创建了多少个线程?
我很困惑.帮我解决一下.