I have a stange a problem.
At first i design a table by the following script
CREATE TABLE MY_TEST
(
TEST_ID INTEGER
)
I also write a class whick is mapping to the table
package junit.entity;
public class MyTest
{
private int testId;
/**
* @return
*/
public int getTestId()
{
return testId;
}
/**
* @param testId */
public void setTestId(int testId)
{
this.testId = testId;
}
}
I write a descriptor in the xml file repository.xml
<class-descriptor class="junit.entity.MyTest" table="MY_TEST">
<field-descriptor autoincrement="true" column="TEST_ID"
jdbc-type="INTEGER" name="testId" primarykey="true"/>
</class-descriptor>
I configure the pool as this
<connection-pool maxActive="20" maxIdle="10" whenExhaustedAction="2"
maxWait="2000" />
this configuration is the same as ojb.properties.
I use the following configuration
ConnectionFactoryClass=org.apache.ojb.broker.accesslayer.ConnectionFactoryPooledImpl
ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl.
I write a multi-thread class to test ojb and have a strange problem
At first i run the class on my computer on oracle9i in the
company.Everything is fine.
Later i run the class on the computer on oracle9i in the client.I found a
connection leak that the connections increase fast.
after a while, it established more than 200 connections.
I got a exception.
org.apache.ojb.broker.PBFactoryException: Borrow broker from pool failed,
using PBKey org.apache.ojb.broker.PBKey: jcdAlias=oracle,
user=ideal_bright, password=*****
at
org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.createPersistenceBroker(Unknown
Source)
at
org.apache.ojb.broker.core.PersistenceBrokerFactoryBaseImpl.defaultPersistenceBroker(Unknown
Source)
at
org.apache.ojb.broker.PersistenceBrokerFactory.defaultPersistenceBroker(Unknown
Source)
at junit.entity.MyTest.main(MyTest.java:86)
Caused by: java.util.NoSuchElementException: Timeout waiting for idle
object
at
org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:782)
... 4 more
I tries many ways ,the result keep the same.
I also run the class on the computer on oracle9i in home.
The same exception happened.
I don't know why.
The following is my code to test ojb.
First this is not a single-thread code.
It result in the same exception.
for (int i = 0; i < 500;i++)
{
try
{
MyTest t_Test = new MyTest();
PersistenceBroker broker =
PersistenceBrokerFactory.defaultPersistenceBroker();
broker.beginTransaction();
broker.store(t_Test);
broker.commitTransaction();
System.out.println(
PersistenceBrokerFactoryFactory.instance().activePersistenceBroker());
//It keeps increasing and never decreasing.
//just like 1,2,3,and so on
}
catch (Exception e)
{
e.printStackTrace();
}
}
The following is a multi-thread code to test ojb.
List t_Threads = new ArrayList();
for (int i = 0; i < 500; i++)
{
Thread t_Thread = new Thread()
{
public void run()
{
MyTest t_Test = new MyTest();
PersistenceBroker broker =
PersistenceBrokerFactory.defaultPersistenceBroker();
broker.beginTransaction();
broker.store(t_Test);
broker.commitTransaction();
System.err.println(
PersistenceBrokerFactoryFactory.instance().activePersistenceBroker());
//It keeps increasing and never decreasing.
//just like 1,2,3,and so on
}
};
t_Threads.add(t_Thread);
}
for (int i = 0; i < t_Threads.size(); i++)
{
Thread t_Thread = (Thread) t_Threads.get(i);
t_Thread.start();
}
Is there anybody can provider a solution to me,
Thanks much.
_________________________________________________________________
享用世界上最大的电子邮件系统― MSN Hotmail。 http://www.hotmail.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]