Re: opening multiple databases from same program
Noel Grandin <[email protected]> Mon, 12 Jul 2010 16:08:24 +0200
| Newsgroups | gmane.comp.java.orm.simpleorm |
|---|---|
| Message-ID | <[email protected]> |
Hi Yeah, but SwingWorker adds a lot of noise to your codebase, and it should only really be necessary for long-running things. And my embedded database (H2) is pretty fast, so it shouldn't be necessary. Doing detachFromThread() is working for me, so I'm going with that. -- Noel Grandin [email protected] wrote: > > > No SwingWorker? These have their own thread. > > Envoyé par mon BlackBerry Wireless Handheld. > > ------------------------------------------------------------------------------------------------------------------------ > *From: * Noel Grandin <[email protected]> > *Sender: * [email protected] > *Date: *Mon, 12 Jul 2010 14:44:22 +0200 > *To: *John Abraham<[email protected]> > *ReplyTo: * [email protected] > *Cc: *<[email protected]> > *Subject: *Re: [SimpleORM] opening multiple databases from same program > > > > Hi > > In Swing, a lot of operations are required to happen on the event thread, which means I end up often talking to the DB > on the event thread, which in turn means that the two UIs both try and talk to the DB from the event thread. > > Sigh. Looks like I'm going to have to call > SSessionJdbc.open() > .. do some stuff.... > SSessionJdbc.commitAndDetachDataSet(); > SSessionJdbc.detachFromThread(); > everywhere I touch the DB. > > (Note: I'm not closing it because I'm reusing connections - it is very expensive to open and close an embedded database!) > > -- Noel > > > John Abraham wrote: > >> I agree that multiple sessions per thread would sometimes be useful, and would support any enhancements in that >> direction. But in your particular case, Noel, can you not just use two threads, one per UI? >> >> -- >> John Abraham >> >> >> On 2010-07-12, at 7:54 AM, Noel Grandin wrote: >> >>> >>> >>> Hi >>> >>> I have 2 embedded databases, and normally one UI runs on each database. But in a particular situation, the two UIs >>> will be running the in same VM at the same time, and thus need access to both databases. >>> >>> I understand what the check is trying to achieve, but it would be better if it checked that there was only one >>> session per database per thread. >>> This should be possible by calling >>> javax.sql.Connection#getMetaData()->getURL() >>> >>> Alternatively, could we get a mechanism for disabling the check? >>> >>> Thanks, Noel Grandin >>> >>> Franck Routier wrote: >>> >>>> >>>> >>>> Hi, >>>> >>>> well, AFAIK, you can't do that... ! >>>> >>>> SSessionJdbc has built-in checks that a connection is single threaded >>>> using a ThreadLocal object. [I think Hibernate has some kind of best >>>> practice to achieve the same goal (I'm not formal here, I didn't use >>>> hibernate for years)] >>>> >>>> There is only one dataSource per SSessionJdbc and one SSessionJdbc per >>>> thread. >>>> >>>> You could implement a different strategy to handle this part. Some work >>>> was done along this path in a previous version of Simpleorm, for using a >>>> single JTA transaction per session. But it is not maintained. >>>> See simpleorm/extras/SConnectionEJB.java >>>> >>>> My question would be : what are you trying to achieve ? >>>> >>>> Franck >>>> >>>> Le vendredi 09 juillet 2010 à 17:11 +0200, Noel Grandin a écrit : >>>> > >>>> > Hi >>>> > >>>> > I'm opening multiple different databases from the same thread, which >>>> > is triggering this check: >>>> > >>>> > simpleorm.utils.SException$Error: Thread's SSession already open [SS >>>> > 1.SkyMon] >>>> > [0@17:08:40.976] !SE>: at >>>> > simpleorm.sessionjdbc.SSessionJdbc.innerOpen(SSessionJdbc.java:129) >>>> > [0@17:08:40.976] !SE>: at >>>> > simpleorm.sessionjdbc.SSessionJdbc.open(SSessionJdbc.java:88) >>>> > [0@17:08:40.976] !SE>: at >>>> > simpleorm.sessionjdbc.SSessionJdbc.open(SSessionJdbc.java:108) >>>> > >>>> > >>>> > What do I do? >>>> > >>>> > Thanks, Noel Grandin >>>> > >>>> > >>>> > >>>> > >>>> > >>>> > >>>> > >>>> > __________________________________________________________ >>>> > Disclaimer: http://www.peralex.com/disclaimer.html <http://www.peralex.com/disclaimer.html> >>>> > >>>> > >>>> > >>>> > >>>> > >>>> >>> >>> >>> >>> ------------------------------------------------------------------------------------------------------------------------ >>> Disclaimer: http://www.peralex.com/disclaimer.html <http://www.peralex.com/disclaimer.html> >>> >>> >> > > > > ------------------------------------------------------------------------------------------------------------------------ > Disclaimer: http://www.peralex.com/disclaimer.html <http://www.peralex.com/disclaimer.html> > > Disclaimer: http://www.peralex.com/disclaimer.html