基于C3P0 ComboPooledDataSource类创建了一个Datasource类。它适用于测试代码但不能在tomcat容器下的servlet中工作。有谁知道为什么?
class Datasource{
private ComboPooledDataSource cpds;
private Datasoruce datasource;
private Datasource(){
//setup cpds
cpds.new ComboPooledDataSource();
cpds.setUser("abcd");
...
}
public static getInstance(){
if( datasource == null ) datasource = new Datasource();
return datasource;
}
public Connection getConnection(){
return cpds.getConnection();
}
}
//test code works if put in indepedent main() with multithreading.
Datasource ds = Datasource.getInstance();
Connection conn = ds.getConnection();
//Above test code won't work if put inside servlet doGet() with tomcat.
错误是"客户端尝试签出连接的尝试已在getConnection()的行中超时。