Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Connection pool with 1 shared connection for all reading a writing

I'm sorry I forgot. Good question.
 I attached stripped log from application. Real code is more complex than simplified sample. 'Persist' is invoked on SwingWorker and 'Select' on AWT-Event-Queue order is guaranteed. em2.createEM is always called after em1.close().
I hope that my code is correct.

EntityManagerFactory emf = ...;
EntityManager em1;
EntityManager em2;

em1 = emf.createEntityManager();
em1.getTransaction().begin()                        //-- transaction begin

em1.persist(<entity>);
em1.flush();
em1.clear();
em1.getTransaction().commit();                        //-- transaction commit
em1.close();

em2 = emf.createEntityManager();             // -- no transaction begin
List<Entity> list = em2.createQuery("select object(o) from Entity as o");
em2.close();

-- EclipseLink LOG --

[EL Finer]: 2011-04-12 14:32:07.377--ClientSession(10665941)--Connection(23986260)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--begin transaction
[EL Finest]: 2011-04-12 14:32:07.378--UnitOfWork(16106406)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--Execute query UpdateObjectQuery(com.crcdata.rl3.data.tx.rb2.RB2Tx[id=2 -- com.crcdata.rl3.data.tx.rb2.RB2Tx@2[null]])
[EL Fine]: 2011-04-12 14:32:07.38--ClientSession(10665941)--Connection(23986260)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--UPDATE TRANSMITTERS SET "LAST_CHANGE" = ?, "RECORD_STATE" = ?, "RECORD_DATE_TO" = ? WHERE ("ID" = ?)
    bind => [2011-04-12 14:32:07.379, 2, 2011-04-12 14:32:07.356, 2]
[EL Finest]: 2011-04-12 14:32:07.384--UnitOfWork(16106406)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--Execute query InsertObjectQuery(com.crcdata.rl3.data.tx.rb2.RB2Tx[id=3 -- com.crcdata.rl3.data.tx.rb2.RB2Tx@3[java.beans.PropertyChangeSupport@1201a5c]])
[EL Fine]: 2011-04-12 14:32:07.386--ClientSession(10665941)--Connection(23986260)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--INSERT INTO TRANSMITTERS ("ID", ...) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    bind => [3, ...]
[EL Finest]: 2011-04-12 14:32:07.411--UnitOfWork(16106406)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--Execute query DataModifyQuery()
[EL Fine]: 2011-04-12 14:32:07.412--ClientSession(10665941)--Connection(23986260)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--INSERT INTO PAR_TX_S ("ID_OBJ", "VALUE", ID_PARAM) VALUES (?, ?, ?)
    bind => [3, nevim, 1]
[EL Finer]: 2011-04-12 14:32:07.415--UnitOfWork(16106406)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--initialize identitymaps
[EL Finer]: 2011-04-12 14:32:07.417--UnitOfWork(16106406)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--begin unit of work commit
[EL Finer]: 2011-04-12 14:32:07.417--ClientSession(10665941)--Connection(23986260)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--commit transaction
[EL Config]: 2011-04-12 14:32:07.418--ServerSession(19321397)--Connection(23986260)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--disconnect
[EL Finer]: 2011-04-12 14:32:07.419--UnitOfWork(16106406)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--end unit of work commit
[EL Finer]: 2011-04-12 14:32:07.419--UnitOfWork(16106406)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--resume unit of work
[EL Finer]: 2011-04-12 14:32:07.423--UnitOfWork(16106406)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--release unit of work
[EL Finer]: 2011-04-12 14:32:07.423--ClientSession(10665941)--Thread(Thread[SwingWorker-pool-2-thread-2,5,main])--client released
Unlocked - events: 4  Lock dur: 72.992649     Unlock dur: 1.22258
[EL Finer]: 2011-04-12 14:32:07.449--ServerSession(19321397)--Thread(Thread[AWT-EventQueue-0,6,main])--client acquired
[EL Finest]: 2011-04-12 14:32:07.45--UnitOfWork(20201007)--Thread(Thread[AWT-EventQueue-0,6,main])--Execute query ReadAllQuery(referenceClass=RB2Tx sql="SELECT "ID", ... FROM TRANSMITTERS WHERE ("EXTID" = ?) ORDER BY "RECORD_DATE_FROM" DESC")
[EL Fine]: 2011-04-12 14:32:07.45--ServerSession(19321397)--Connection(10991242)--Thread(Thread[AWT-EventQueue-0,6,main])--SELECT "ID", ... FROM TRANSMITTERS WHERE ("EXTID" = ?) ORDER BY "RECORD_DATE_FROM" DESC
    bind => [1]
[EL Finer]: 2011-04-12 14:32:07.46--UnitOfWork(20201007)--Thread(Thread[AWT-EventQueue-0,6,main])--release unit of work
[EL Finer]: 2011-04-12 14:32:07.46--ClientSession(3726796)--Thread(Thread[AWT-EventQueue-0,6,main])--client released

----- Original Message -----
From: "Christopher Delahunt" <christopher.delahunt@xxxxxxxxxx>
To: "EclipseLink User Discussions" <eclipselink-users@xxxxxxxxxxx>
Sent: Tuesday, April 12, 2011 1:44:26 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: Re: [eclipselink-users] Connection pool with 1 shared connection for all reading a writing

How are you starting and committing your transactions?  Em2 will not see changes in em1 until the transaction commits - unless it uses the same connection.

Regards,
Chris

On 2011-04-12, at 4:49 AM, Janda Martin <jandam@xxxxxxxxxx> wrote:

Thank you for link. I think it will help.

I suppose that problem is in JDBC driver or maybe its my misuse of JPA.

This is sample code that make my decision to access DB only through 1 connection.
Call persist and select.

EntityManagerFactory emf = ...;
EntityManager em1;
EntityManager em2;

em1 = emf.createEntityManager();

em1.persist(<entity>);
em1.flush();
em1.clear();
em1.close();

em2 = emf.createEntityManager();
List<Entity> list = em2.createQuery("select object(o) from Entity as o");
em2.close();

According to EclipseLink log:

Everything is OK when em1 and em2 uses same connection. list contains <entity> as supposed.

When em2 uses different connection from em1 list don't contain persisted <entity>.

I think that bug is in JDBC driver.
*) It doesn't allow change transaction isolation level.
*) maybe it will work when em1 connection is closed and then opened another connection in em2



----- Original Message -----
From: "Rohit Banga" <rohit.banga@xxxxxxxxxx>
To: "rohit banga" <rohit.banga@xxxxxxxxxx>, "EclipseLink User Discussions" <eclipselink-users@xxxxxxxxxxx>
Sent: Tuesday, April 12, 2011 10:24:43 AM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: Re: [eclipselink-users] Connection pool with 1 shared connection for all reading a writing

But on second thoughts, since your driver can provide just one connection how can you possibly share it among different threads? You need a way to sequence your messages to the DBMS.

On 4/12/2011 1:49 PM, Rohit Banga wrote:
Hi Martin

You can consider using a third-party connection pool like Universal Connection Pool (UCP).

The following link should be useful:

http://onpersistence.blogspot.com/2008/04/eclipselink-and-datasources.html

Let me know if the above works for you. You may need to tweak the code a bit.

On 4/12/2011 1:34 PM, Janda Martin wrote:
Please can you help me. 

Due to bugs in prehistoric third party JDBC driver we are forced to access database through only one shared connection for reading and writing.

Environment:
Java SE 6u24, Eclipselink 2.1.2, platform MS Access


I tried to limit connection pool that solved the problem with shared connection for reading/writing

            <property name="eclipselink.jdbc.connections.initial" value="0"/>
            <property name="eclipselink.jdbc.connections.min" value="0"/>
            <property name="eclipselink.jdbc.connections.max" value="1"/>
            
            <property name="eclipselink.jdbc.connection_pool.read.shared" value="true"/>
            <property name="eclipselink.jdbc.read-connections.shared" value="true"/>

There is problem when I want access DB from multiple threads. Because other waits on Connection Pool for releasing connection.

Typical scenario: 
 1st thread - works ScrollableCursor
 2nd thread - try to execute ReadAllQuery (select * from...)

ReadAllQuery is waiting for connection that is held by ScrollableCursor

I think that is possible to implement custom connection pool.


Question: is there any documentation/tutorial or code sample that shows how to implement connection pool for EclipseLink 2.1.2. Would it work for EclipseLink 2.2, newer versions?


Thank you very much for help

 Martin

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--
Thanks and Regards
Rohit Banga
Member Technical Staff
Oracle Server Technologies
_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--
Thanks and Regards
Rohit Banga
Member Technical Staff
Oracle Server Technologies

_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Back to the top